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", () => {
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),
+9 -12
View File
@@ -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;
}