feat: restart renovation after github error

When 404 or 422 errors are encountered writing updates, Renovate will now restart in an attempt to fix it. Usually this is because branches/PRs have been edited or closed while Renovate is running.

Closes #1299
This commit is contained in:
Rhys Arkins 2017-12-26 06:26:33 +01:00
parent f8b78ac347
commit eb579ff388
5 changed files with 20 additions and 0 deletions

View file

@ -116,6 +116,11 @@ async function processBranch(branchConfig) {
config.forcePr = true;
}
} catch (err) {
// istanbul ignore if
if (err.statusCode === 404 || err.statusCode === 422) {
logger.warn({ err }, `Error updating branch: ${err.message}`);
return 'platform-error';
}
logger.error({ err }, `Error updating branch: ${err.message}`);
// Don't throw here - we don't want to stop the other renovations
return 'error';

View file

@ -32,6 +32,10 @@ async function renovateRepository(repoConfig, token, loop = 1) {
logger.info('Restarting repo renovation after automerge');
return renovateRepository(repoConfig, token, loop + 1);
}
if (res === 'platform-error') {
logger.info('Restarting renovation after platform error');
return renovateRepository(repoConfig, token, loop + 1);
}
return res;
} catch (err) {
return handleError(config, err);

View file

@ -21,6 +21,9 @@ async function writeUpdates(config) {
// Stop procesing other branches because base branch has been changed by an automerge
return 'automerged';
}
if (res === 'platform-error') {
return 'platform-error';
}
}
return 'done';
} finally {

View file

@ -28,6 +28,7 @@ describe('workers/repository', () => {
it('writes', async () => {
determineUpdates.mockReturnValue({ repoIsOnboarded: true });
writeUpdates.mockReturnValueOnce('automerged');
writeUpdates.mockReturnValueOnce('platform-error');
writeUpdates.mockReturnValueOnce('onboarded');
const res = await renovateRepository(config, 'some-token');
expect(res).toMatchSnapshot();

View file

@ -25,5 +25,12 @@ describe('workers/repository/write', () => {
expect(res).toEqual('automerged');
expect(branchWorker.processBranch.mock.calls).toHaveLength(2);
});
it('stops after platform error', async () => {
config.branches = [{}, {}];
branchWorker.processBranch.mockReturnValueOnce('platform-error');
const res = await writeUpdates(config);
expect(res).toEqual('platform-error');
expect(branchWorker.processBranch.mock.calls).toHaveLength(1);
});
});
});