Skip to content

Commit 6d918a6

Browse files
herdiyana256alan-agius4
authored andcommitted
fix(ng-dev): handle the 409 GitHub returns when a validated PR head moved (#3911)
Pinning the API merge to the validated head SHA means GitHub now rejects the merge with a 409 if the head moved after validation, but that error was falling through to the generic `throw e` and surfacing as a raw Octokit exception instead of a clear, actionable message. Adds a branch alongside the existing 403/404 handling that catches the 409 and raises a FatalMergeToolError explaining what happened (the head changed after validation) and what to do (re-run the merge). PR Close #3911
1 parent 2c79341 commit 6d918a6

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

.github/local-actions/branch-manager/main.js

Lines changed: 10 additions & 1 deletion
Large diffs are not rendered by default.

ng-dev/pr/merge/strategies/api-merge.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,16 @@ export class GithubApiMergeStrategy extends AutosquashMergeStrategy {
144144
if (isGithubApiError(e) && (e.status === 403 || e.status === 404)) {
145145
throw new FatalMergeToolError('Insufficient Github API permissions to merge pull request.');
146146
}
147+
// Github returns `409` when the `sha` we pinned the merge to no longer matches the pull
148+
// request's actual head. That means the pull request's head moved after it was validated
149+
// (approvals, CI status) but before this merge call went out.
150+
if (isGithubApiError(e) && e.status === 409) {
151+
throw new FatalMergeToolError(
152+
`Pull request head commit changed after it was validated (expected ${headSha}). ` +
153+
`Merging now would land commits that were never reviewed or checked. Please re-run ` +
154+
`the merge so the new head is validated.`,
155+
);
156+
}
147157
throw e;
148158
}
149159

0 commit comments

Comments
 (0)