From ab987941ac27b4aeb97a890eba950d4fce1eb507 Mon Sep 17 00:00:00 2001 From: Rhys Arkins Date: Thu, 9 Jul 2020 07:26:22 +0200 Subject: [PATCH] fix(github): delete fork after patch failure --- lib/platform/github/index.ts | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/platform/github/index.ts b/lib/platform/github/index.ts index 32a0431ed523da..8811189921db3b 100644 --- a/lib/platform/github/index.ts +++ b/lib/platform/github/index.ts @@ -380,15 +380,19 @@ export async function initRepo({ } ); } catch (err) /* istanbul ignore next */ { + logger.debug( + 'Error updating fork reference - will try deleting fork to try again next time' + ); + try { + await githubApi.deleteJson(`repos/${config.repository}`); + logger.info('Fork deleted'); + } catch (deleteErr) { + logger.warn({ err: deleteErr }, 'Could not delete fork'); + } if (err instanceof ExternalHostError) { throw err; } - if ( - err.statusCode === 422 && - err.message.startsWith('Object does not exist') - ) { - throw new Error(REPOSITORY_CHANGED); - } + throw new ExternalHostError(err); } } else { logger.debug({ repository_fork: config.repository }, 'Created fork');