Skip to content
Snippets Groups Projects
Commit 7ae3ce32 authored by Rhys Arkins's avatar Rhys Arkins
Browse files

fix(automerge): handle github branch protection failures

parent eef58e2e
No related branches found
Tags 24.60.3
No related merge requests found
...@@ -38,13 +38,40 @@ export async function tryBranchAutomerge( ...@@ -38,13 +38,40 @@ export async function tryBranchAutomerge(
} }
logger.info({ branch: config.branchName }, 'Branch automerged'); logger.info({ branch: config.branchName }, 'Branch automerged');
return 'automerged'; // Branch no longer exists return 'automerged'; // Branch no longer exists
} catch (err) { } catch (err) /* istanbul ignore next */ {
// istanbul ignore if
if (err.message === 'not ready') { if (err.message === 'not ready') {
logger.debug('Branch is not ready for automerge'); logger.debug('Branch is not ready for automerge');
return 'not ready'; 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'; return 'failed';
} }
} else if (branchStatus === BranchStatus.red) { } else if (branchStatus === BranchStatus.red) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment