fix(onboarding): delete onboarding PR branch if pr not found

This commit is contained in:
Rhys Arkins 2018-07-22 09:07:31 +02:00
parent bb28ae27a2
commit efa5edbdf3

View file

@ -1,3 +1,4 @@
const is = require('@sindresorhus/is');
const { getConfigDesc } = require('./config-description');
const { getErrors, getWarnings } = require('./errors-warnings');
const { getBaseBranchDesc } = require('./base-branch');
@ -78,14 +79,32 @@ You can post questions in [our Config Help repository](https://github.com/renova
logger.info('Creating onboarding PR');
const labels = [];
const useDefaultBranch = true;
const pr = await platform.createPr(
onboardingBranch,
onboardingPrTitle,
prBody,
labels,
useDefaultBranch
);
logger.info({ pr: pr.displayNumber }, 'Created onboarding PR');
try {
const pr = await platform.createPr(
onboardingBranch,
onboardingPrTitle,
prBody,
labels,
useDefaultBranch
);
logger.info({ pr: pr.displayNumber }, 'Created onboarding PR');
} catch (err) /* istanbul ignore next */ {
if (
err.statusCode === 422 &&
err.response &&
err.response.body &&
!is.empty(err.response.body.errors) &&
err.response.body.errors[0].message &&
err.response.body.errors[0].message.startsWith(
'A pull request already exists'
)
) {
logger.info('Onboarding PR already exists but cannot find it');
await platform.deleteBranch(onboardingBranch);
return;
}
throw err;
}
}
module.exports = {