Prioritize shipping actions in git controls

This commit is contained in:
Mohamed Boudra
2026-06-03 22:12:27 +07:00
parent c44ad7ecd1
commit b510244518
2 changed files with 50 additions and 36 deletions
+41 -24
View File
@@ -366,45 +366,62 @@ describe("git-actions-policy", () => {
); );
}); });
it("respects the ship preference when choosing between PR merge and local merge", () => { it("promotes ready PR merge over update-from-base", () => {
const prPreferredActions = buildGitActions( const actions = buildGitActions(
createInput({ createInput({
hasRemote: true, hasRemote: true,
isOnBaseBranch: false, isOnBaseBranch: false,
aheadCount: 2, aheadCount: 2,
behindBaseCount: 3,
hasPullRequest: true, hasPullRequest: true,
pullRequestUrl: "https://example.com/pr/456", pullRequestUrl: "https://example.com/pr/456",
pullRequestState: "open", pullRequestState: "open",
pullRequestMergeable: "MERGEABLE", pullRequestMergeable: "MERGEABLE",
pullRequestGithub: githubStatus(), pullRequestGithub: githubStatus({ mergeStateStatus: "CLEAN" }),
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",
}), }),
); );
expect(prPreferredActions.primary).toMatchObject({ expect(actions.primary).toMatchObject({
id: "merge-pr-squash", id: "merge-pr-squash",
label: "Squash and merge", 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", id: "merge-branch",
label: "Merge locally", 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", () => { 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( expect(actions.secondary.some((action) => action.id.startsWith("enable-pr-auto-merge"))).toBe(
false, 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( expect(
actions.secondary.some((action) => actions.secondary.some((action) =>
["merge-pr-squash", "merge-pr-merge", "merge-pr-rebase"].includes(action.id), ["merge-pr-squash", "merge-pr-merge", "merge-pr-rebase"].includes(action.id),
+9 -12
View File
@@ -336,24 +336,21 @@ function getPrimaryActionId(input: BuildGitActionsInput): GitActionId | null {
if (canPush(input)) { if (canPush(input)) {
return "push"; 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)) { if (!input.isOnBaseBranch && canMergeFromBase(input)) {
return "merge-from-base"; 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) { if (input.githubFeaturesEnabled && input.hasPullRequest && input.pullRequestUrl) {
return "pr"; return "pr";
} }
if (!input.isOnBaseBranch && input.aheadCount > 0) {
return "pr";
}
return null; return null;
} }