Allow PR merge when GitHub reports it ready (#1172)

This commit is contained in:
Mohamed Boudra
2026-05-25 10:05:35 +00:00
committed by GitHub
parent 8a2e5c786e
commit 1e68283565
2 changed files with 51 additions and 7 deletions
+42
View File
@@ -226,6 +226,9 @@ describe("git-actions-policy", () => {
"merge-from-base",
"merge-branch",
"pr",
"merge-pr-squash",
"merge-pr-merge",
"merge-pr-rebase",
]);
expect(
actions.secondary.some((action) => action.id === "pr" && action.label === "View PR"),
@@ -324,6 +327,45 @@ describe("git-actions-policy", () => {
});
});
it("offers direct PR merge when GitHub says the PR is mergeable even if the local branch is behind", () => {
const actions = buildGitActions(
createInput({
hasRemote: true,
isOnBaseBranch: false,
aheadCount: 2,
behindBaseCount: 3,
aheadOfOrigin: 0,
behindOfOrigin: 2,
hasPullRequest: true,
pullRequestUrl: "https://example.com/pr/456",
pullRequestState: "open",
pullRequestMergeable: "MERGEABLE",
pullRequestGithub: githubStatus({ mergeStateStatus: "CLEAN" }),
shipDefault: "pr",
}),
);
expect(actions.secondary).toEqual(
expect.arrayContaining([
expect.objectContaining({
id: "merge-pr-squash",
disabled: false,
unavailableMessage: undefined,
}),
expect.objectContaining({
id: "merge-pr-merge",
disabled: false,
unavailableMessage: undefined,
}),
expect.objectContaining({
id: "merge-pr-rebase",
disabled: false,
unavailableMessage: undefined,
}),
]),
);
});
it("respects the ship preference when choosing between PR merge and local merge", () => {
const prPreferredActions = buildGitActions(
createInput({
+9 -7
View File
@@ -504,7 +504,7 @@ function canMergeFromBase(input: BuildGitActionsInput): boolean {
function canMergePr(input: BuildGitActionsInput): boolean {
const github = input.pullRequestGithub;
const canMergeFromTopLevelStatus =
const canMergeFromPullRequestStatus =
input.githubFeaturesEnabled &&
input.hasPullRequest &&
input.pullRequestState === "open" &&
@@ -512,17 +512,19 @@ function canMergePr(input: BuildGitActionsInput): boolean {
!input.pullRequestIsMerged &&
input.pullRequestMergeable !== "CONFLICTING" &&
input.aheadCount > 0 &&
!input.hasUncommittedChanges &&
input.behindOfOrigin === 0 &&
input.aheadOfOrigin === 0 &&
!canMergeFromBase(input);
!input.hasUncommittedChanges;
if (!canMergeFromTopLevelStatus) {
if (!canMergeFromPullRequestStatus) {
return false;
}
if (!hasPullRequestGithubFacts(github)) {
return input.pullRequestMergeable === "MERGEABLE";
return (
input.pullRequestMergeable === "MERGEABLE" &&
input.behindOfOrigin === 0 &&
input.aheadOfOrigin === 0 &&
!canMergeFromBase(input)
);
}
return (