Skip to content

Commit e7eea88

Browse files
committed
fix(web): thread details PR merge uses the last selected merge method
The thread details panel's PR row always preferred a merge commit, ignoring the project's default merge method and the method last chosen in the PR panel. It now resolves the method the same way as the PR panel and speed actions.
1 parent ca140c4 commit e7eea88

4 files changed

Lines changed: 55 additions & 13 deletions

File tree

‎apps/web/src/components/chat/ThreadDetailsPrRow.browser.test.tsx‎

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { userEvent } from "vite-plus/test/browser";
1515
const state = vi.hoisted(() => ({
1616
status: "success" as PullRequestCheck["status"],
1717
extraStatus: null as PullRequestCheck["status"] | null,
18+
mergeMethods: ["merge"] as Array<"merge" | "squash" | "rebase">,
1819
perform: vi.fn(),
1920
newThread: vi.fn(),
2021
prepareThread: vi.fn(),
@@ -54,9 +55,13 @@ const queryData = () => ({
5455
description: null,
5556
url: null,
5657
})),
57-
capabilities: { actions: ["merge"], mergeMethods: ["merge"] },
58+
capabilities: { actions: ["merge"], mergeMethods: state.mergeMethods },
5859
viewerPermissions: { actions: ["merge"] },
59-
mergeCapabilities: { merge: true, squash: false, rebase: false },
60+
mergeCapabilities: {
61+
merge: state.mergeMethods.includes("merge"),
62+
squash: state.mergeMethods.includes("squash"),
63+
rebase: state.mergeMethods.includes("rebase"),
64+
},
6065
});
6166
vi.mock(import("~/state/query"), async (importOriginal) => ({
6267
...(await importOriginal()),
@@ -105,8 +110,41 @@ vi.mock(import("../ui/toast"), async (original) => {
105110
});
106111

107112
import { act, render as renderUi } from "../../../test/render";
113+
import { useUiStateStore } from "~/uiStateStore";
108114
import { ThreadDetailsPrRow } from "./ThreadDetailsPrRow";
109115

116+
it("merges with the last selected merge method", async () => {
117+
await using screen = await setup();
118+
const { container } = screen;
119+
state.mergeMethods = ["merge", "squash"];
120+
useUiStateStore.getState().setPullRequestMergeMethod("squash");
121+
await act(async () => {
122+
await screen.rerender(
123+
<ThreadDetailsPrRow
124+
environmentId={EnvironmentId.make("environment")}
125+
pr={null}
126+
number={1}
127+
status={null}
128+
project={null}
129+
label="Test PR"
130+
openAriaLabel="Open PR"
131+
onOpen={vi.fn()}
132+
/>,
133+
);
134+
});
135+
const clickMerge = async (scope: ParentNode) =>
136+
await act(async () => {
137+
[...scope.querySelectorAll("button")]
138+
.find((button) => button.textContent?.trim() === "Merge")!
139+
.click();
140+
});
141+
await clickMerge(container);
142+
const dialog = document.querySelector('[role="alertdialog"]')!;
143+
expect(dialog.textContent).toContain("using squash");
144+
await clickMerge(dialog);
145+
expect(state.perform).toHaveBeenCalledWith("merge", "squash");
146+
});
147+
110148
it("requires a new merge click after passing checks become pending and pass again", async () => {
111149
await using screen = await setup();
112150
const { container } = screen;
@@ -265,5 +303,7 @@ async function setup() {
265303

266304
state.status = "success";
267305
state.extraStatus = null;
306+
state.mergeMethods = ["merge"];
307+
useUiStateStore.getState().setPullRequestMergeMethod("merge");
268308
return renderUi(null);
269309
}

‎apps/web/src/components/chat/ThreadDetailsPrRow.tsx‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { usePullRequestChecksRefresh } from "~/hooks/usePullRequestChecksRefresh
2121
import { cn } from "~/lib/utils";
2222
import { useServerConfigs } from "~/state/entities";
2323
import { pullRequestEnvironment } from "~/state/pullRequests";
24+
import { useUiStateStore } from "~/uiStateStore";
2425
import {
2526
useEnvironmentQueryIsNewer,
2627
useEnvironmentQueryRefresh,
@@ -33,7 +34,7 @@ import {
3334
classifyPullRequestChecks,
3435
describePullRequestChecks,
3536
isPullRequestConflicting,
36-
resolveSelectedMergeMethod,
37+
resolvePullRequestMergeMethod,
3738
allowedPullRequestMergeMethods,
3839
resolveThreadPanelPullRequestAction,
3940
} from "../pullRequest/pullRequestDetail.logic";
@@ -46,6 +47,7 @@ import {
4647
} from "../pullRequest/pullRequestPresentation";
4748
import {
4849
usePullRequestActionRunner,
50+
usePullRequestDefaultMergeMethodResolver,
4951
usePullRequestHandoffs,
5052
} from "../pullRequest/usePullRequestActions";
5153
import {
@@ -166,6 +168,11 @@ export function ThreadDetailsPrRow({
166168
},
167169
});
168170
const { handoff, startHandoff } = usePullRequestHandoffs({ environmentId, detail });
171+
const lastSelectedMergeMethod = useUiStateStore((state) => state.pullRequestMergeMethod);
172+
const resolveProjectDefaultMergeMethod = usePullRequestDefaultMergeMethodResolver(
173+
environmentId,
174+
(project?.id as ProjectId | undefined) ?? null,
175+
);
169176
const [confirmingMerge, setConfirmingMerge] = useState(false);
170177

171178
const rowAction = resolveThreadPanelPullRequestAction(detail);
@@ -175,9 +182,11 @@ export function ThreadDetailsPrRow({
175182
const conflicting = isPullRequestConflicting(detail);
176183
const checksState = detail === null ? "none" : classifyPullRequestChecks(detail.checks);
177184
const checksRollup = detail === null ? null : pullRequestChecksState(detail.checks);
178-
const selectedMergeMethod = resolveSelectedMergeMethod(
185+
const selectedMergeMethod = resolvePullRequestMergeMethod(
179186
allowedPullRequestMergeMethods(detail),
180-
"merge",
187+
null,
188+
resolveProjectDefaultMergeMethod(),
189+
lastSelectedMergeMethod,
181190
);
182191

183192
const startResolveConflicts = () => {

‎apps/web/src/components/pullRequest/pullRequestDetail.logic.ts‎

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -292,13 +292,6 @@ export function allowedPullRequestMergeMethods(
292292
: detail.capabilities.mergeMethods.filter((method) => detail.mergeCapabilities[method]);
293293
}
294294

295-
export function resolveSelectedMergeMethod(
296-
allowedMergeMethods: ReadonlyArray<PullRequestMergeMethod>,
297-
preferred: PullRequestMergeMethod,
298-
): PullRequestMergeMethod {
299-
return allowedMergeMethods.includes(preferred) ? preferred : (allowedMergeMethods[0] ?? "merge");
300-
}
301-
302295
function canPerformPullRequestAction(
303296
detail: Pick<PullRequestActionableDetail, "capabilities" | "viewerPermissions"> | null,
304297
action: PullRequestAction,

‎apps/web/src/components/pullRequest/usePullRequestActions.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ import { pullRequestEntryKey, type EnvironmentPullRequestEntry } from "./pullReq
4242

4343
export function usePullRequestDefaultMergeMethodResolver(
4444
environmentId: EnvironmentId,
45-
projectId: ProjectId,
45+
projectId: ProjectId | null,
4646
) {
4747
const projectDefault = useEnvironmentSettings(
4848
environmentId,

0 commit comments

Comments
 (0)