Skip to content

Commit

Permalink
fix(github): detect pull request already exists error
Browse files Browse the repository at this point in the history
  • Loading branch information
rarkins committed Jun 1, 2019
1 parent 74b8a0d commit b41fc76
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions lib/workers/pr/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,23 +263,26 @@ async function ensurePr(prConfig) {
logger.info({ branch: branchName, pr: pr.number }, 'PR created');
}
} catch (err) /* istanbul ignore next */ {
if (err.message === 'Validation Failed (422)') {
logger.info({ branch: branchName }, 'Deleting invalid branch');
// istanbul ignore if
if (config.dryRun) {
logger.info('DRY-RUN: Would delete branch: ' + config.branchName);
} else {
await platform.deleteBranch(branchName);
logger.debug({ err }, 'Pull request creation error');
if (err.body && err.body.message === 'Validation failed') {
if (err.body.errors && err.body.errors.length) {
if (
err.body.errors.some(
error =>
error.message &&
error.message.startsWith('A pull request already exists')
)
) {
logger.warn('A pull requests already exists');
return null;
}
}
return null;
}
logger.warn({ err }, `Failed to create PR`);
if (err.statusCode === 502) {
logger.info(
logger.warn(
{ branch: branchName },
'Deleting branch due to server error'
);
// istanbul ignore if
if (config.dryRun) {
logger.info('DRY-RUN: Would delete branch: ' + config.branchName);
} else {
Expand Down

0 comments on commit b41fc76

Please sign in to comment.