Skip to content

Commit

Permalink
fix(automerge): handle github branch protection failures
Browse files Browse the repository at this point in the history
  • Loading branch information
rarkins committed Feb 22, 2021
1 parent eef58e2 commit 7ae3ce3
Showing 1 changed file with 30 additions and 3 deletions.
33 changes: 30 additions & 3 deletions lib/workers/branch/automerge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,40 @@ export async function tryBranchAutomerge(
}
logger.info({ branch: config.branchName }, 'Branch automerged');
return 'automerged'; // Branch no longer exists
} catch (err) {
// istanbul ignore if
} catch (err) /* istanbul ignore next */ {
if (err.message === 'not ready') {
logger.debug('Branch is not ready for automerge');
return 'not ready';
}
logger.info({ err }, `Failed to automerge branch`);
if (
err.message.includes('refusing to merge unrelated histories') ||
err.message.includes('Not possible to fast-forward')
) {
logger.warn({ err }, 'Branch is not up to date - cannot automerge');
return 'not ready';
}
if (err.message.includes('Protected branch')) {
if (err.message.includes('status check')) {
logger.debug(
{ err },
'Branch is not ready for automerge: required status checks are remaining'
);
return 'not ready';
}
if (err.stack?.includes('reviewers')) {
logger.info(
{ err },
'Branch automerge is not possible due to branch protection (required reviewers)'
);
return 'failed';
}
logger.info(
{ err },
'Branch automerge is not possible due to branch protection'
);
return 'failed';
}
logger.warn({ err }, 'Unknown error when attempting branch automerge');
return 'failed';
}
} else if (branchStatus === BranchStatus.red) {
Expand Down

0 comments on commit 7ae3ce3

Please sign in to comment.