mirror of
https://github.com/renovatebot/renovate.git
synced 2025-01-12 06:56:24 +00:00
fix: abort renovation if repository has changed during run
If attempting to create a branch and it already exists, or attempting to update a branch and it no longer exists, then we abort.
This commit is contained in:
parent
d186633866
commit
e306f707db
4 changed files with 32 additions and 10 deletions
|
@ -1009,13 +1009,14 @@ async function createBranch(branchName, sha) {
|
||||||
config.branchList.push(branchName);
|
config.branchList.push(branchName);
|
||||||
await get.post(`repos/${config.repository}/git/refs`, options);
|
await get.post(`repos/${config.repository}/git/refs`, options);
|
||||||
} catch (err) /* istanbul ignore next */ {
|
} catch (err) /* istanbul ignore next */ {
|
||||||
if (err.statusCode === 422) {
|
if (
|
||||||
logger.warn('Branch already existed? Attempting update instead');
|
err.statusCode === 422 &&
|
||||||
await updateBranch(branchName, sha);
|
err.message.startsWith('Reference already exists')
|
||||||
} else {
|
) {
|
||||||
logger.debug('Unknown error creating branch');
|
logger.info({ err }, 'Branch already exists - exiting');
|
||||||
throw err;
|
throw new Error('repository-changed');
|
||||||
}
|
}
|
||||||
|
throw err;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1032,10 +1033,21 @@ async function updateBranch(branchName, commit) {
|
||||||
if (config.forkToken) {
|
if (config.forkToken) {
|
||||||
options.token = config.forkToken;
|
options.token = config.forkToken;
|
||||||
}
|
}
|
||||||
await get.patch(
|
try {
|
||||||
`repos/${config.repository}/git/refs/heads/${branchName}`,
|
await get.patch(
|
||||||
options
|
`repos/${config.repository}/git/refs/heads/${branchName}`,
|
||||||
);
|
options
|
||||||
|
);
|
||||||
|
} catch (err) /* istanbul ignore next */ {
|
||||||
|
if (
|
||||||
|
err.statusCode === 422 &&
|
||||||
|
err.message.startsWith('Reference does not exist')
|
||||||
|
) {
|
||||||
|
logger.info({ err }, 'Branch no longer exists - exiting');
|
||||||
|
throw new Error('repository-changed');
|
||||||
|
}
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Low-level commit operations
|
// Low-level commit operations
|
||||||
|
|
|
@ -158,6 +158,11 @@ async function processBranch(branchConfig) {
|
||||||
config.forcePr = true;
|
config.forcePr = true;
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
// istanbul ignore if
|
||||||
|
if (err.message === 'repository-changed') {
|
||||||
|
logger.debug('Passing repository-changed error up');
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
logger.error({ err }, `Error updating branch: ${err.message}`);
|
logger.error({ err }, `Error updating branch: ${err.message}`);
|
||||||
// Don't throw here - we don't want to stop the other renovations
|
// Don't throw here - we don't want to stop the other renovations
|
||||||
return 'error';
|
return 'error';
|
||||||
|
|
|
@ -30,6 +30,10 @@ async function handleError(config, err) {
|
||||||
} else if (err.message === 'loops>5') {
|
} else if (err.message === 'loops>5') {
|
||||||
logger.warn('Repository has looped 5 times already');
|
logger.warn('Repository has looped 5 times already');
|
||||||
return err.message;
|
return err.message;
|
||||||
|
} else if (err.message === 'repository-changed') {
|
||||||
|
logger.warn('Repository has changed during renovation - aborting');
|
||||||
|
delete config.branchList; // eslint-disable-line no-param-reassign
|
||||||
|
return err.message;
|
||||||
} else if (err.message === 'config-validation') {
|
} else if (err.message === 'config-validation') {
|
||||||
delete config.branchList; // eslint-disable-line no-param-reassign
|
delete config.branchList; // eslint-disable-line no-param-reassign
|
||||||
logger.info({ error: err }, 'Repository has invalid config');
|
logger.info({ error: err }, 'Repository has invalid config');
|
||||||
|
|
|
@ -13,6 +13,7 @@ describe('workers/repository/error', () => {
|
||||||
const errors = [
|
const errors = [
|
||||||
'uninitiated',
|
'uninitiated',
|
||||||
'disabled',
|
'disabled',
|
||||||
|
'repository-changed',
|
||||||
'fork',
|
'fork',
|
||||||
'no-package-files',
|
'no-package-files',
|
||||||
'loops>5',
|
'loops>5',
|
||||||
|
|
Loading…
Reference in a new issue