diff --git a/packages/app/src/git/policy.test.ts b/packages/app/src/git/policy.test.ts index c11d2221f..4b21be423 100644 --- a/packages/app/src/git/policy.test.ts +++ b/packages/app/src/git/policy.test.ts @@ -366,45 +366,62 @@ describe("git-actions-policy", () => { ); }); - it("respects the ship preference when choosing between PR merge and local merge", () => { - const prPreferredActions = buildGitActions( + it("promotes ready PR merge over update-from-base", () => { + const actions = buildGitActions( createInput({ hasRemote: true, isOnBaseBranch: false, aheadCount: 2, + behindBaseCount: 3, hasPullRequest: true, pullRequestUrl: "https://example.com/pr/456", pullRequestState: "open", pullRequestMergeable: "MERGEABLE", - pullRequestGithub: githubStatus(), - shipDefault: "pr", - }), - ); - const localMergePreferredActions = buildGitActions( - createInput({ - hasRemote: true, - isOnBaseBranch: false, - aheadCount: 2, - hasPullRequest: true, - pullRequestUrl: "https://example.com/pr/456", - pullRequestState: "open", - pullRequestMergeable: "MERGEABLE", - pullRequestGithub: githubStatus(), - shipDefault: "merge", + pullRequestGithub: githubStatus({ mergeStateStatus: "CLEAN" }), }), ); - expect(prPreferredActions.primary).toMatchObject({ + expect(actions.primary).toMatchObject({ id: "merge-pr-squash", label: "Squash and merge", }); - expect(localMergePreferredActions.primary).toMatchObject({ + }); + + it("promotes local merge over update-from-base", () => { + const actions = buildGitActions( + createInput({ + hasRemote: true, + isOnBaseBranch: false, + aheadCount: 2, + behindBaseCount: 3, + }), + ); + + expect(actions.primary).toMatchObject({ id: "merge-branch", label: "Merge locally", }); - expect( - localMergePreferredActions.secondary.some((action) => action.id === "merge-pr-squash"), - ).toBe(true); + }); + + it("promotes ready PR merge over local merge", () => { + const actions = buildGitActions( + createInput({ + hasRemote: true, + isOnBaseBranch: false, + aheadCount: 2, + hasPullRequest: true, + pullRequestUrl: "https://example.com/pr/456", + pullRequestState: "open", + pullRequestMergeable: "MERGEABLE", + pullRequestGithub: githubStatus(), + }), + ); + + expect(actions.primary).toMatchObject({ + id: "merge-pr-squash", + label: "Squash and merge", + }); + expect(actions.secondary.some((action) => action.id === "merge-branch")).toBe(true); }); it("keeps the merge-pr actions in the feature branch menu", () => { @@ -648,7 +665,7 @@ describe("git-actions-policy", () => { }), ); - expect(actions.primary).toMatchObject({ id: "pr", label: "View PR" }); + expect(actions.primary).toMatchObject({ id: "merge-branch", label: "Merge locally" }); expect(actions.secondary.some((action) => action.id.startsWith("enable-pr-auto-merge"))).toBe( false, ); @@ -748,7 +765,7 @@ describe("git-actions-policy", () => { }), ); - expect(actions.primary).toMatchObject({ id: "pr", label: "View PR" }); + expect(actions.primary).toMatchObject({ id: "merge-branch", label: "Merge locally" }); expect( actions.secondary.some((action) => ["merge-pr-squash", "merge-pr-merge", "merge-pr-rebase"].includes(action.id), diff --git a/packages/app/src/git/policy.ts b/packages/app/src/git/policy.ts index 5388dd8c4..f249df4d7 100644 --- a/packages/app/src/git/policy.ts +++ b/packages/app/src/git/policy.ts @@ -336,24 +336,21 @@ function getPrimaryActionId(input: BuildGitActionsInput): GitActionId | null { if (canPush(input)) { return "push"; } + if (canMergePr(input)) { + return getDefaultDirectPullRequestMergeActionId(input); + } + if (canEnablePrAutoMerge(input)) { + return getDefaultEnablePullRequestAutoMergeActionId(input); + } + if (!input.isOnBaseBranch && input.aheadCount > 0) { + return "merge-branch"; + } if (!input.isOnBaseBranch && canMergeFromBase(input)) { return "merge-from-base"; } - if (canMergePr(input) && input.shipDefault === "pr") { - return getDefaultDirectPullRequestMergeActionId(input); - } - if (canEnablePrAutoMerge(input) && input.shipDefault === "pr") { - return getDefaultEnablePullRequestAutoMergeActionId(input); - } - if (!input.isOnBaseBranch && input.aheadCount > 0 && input.shipDefault === "merge") { - return "merge-branch"; - } if (input.githubFeaturesEnabled && input.hasPullRequest && input.pullRequestUrl) { return "pr"; } - if (!input.isOnBaseBranch && input.aheadCount > 0) { - return "pr"; - } return null; }