Skip to content

Commit cf2fe5c

Browse files
committed
fix(web): preserve review drafts and environment names across terminology changes
1 parent 1c29cd5 commit cf2fe5c

5 files changed

Lines changed: 122 additions & 67 deletions

File tree

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

Lines changed: 58 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -916,49 +916,65 @@ describe("one finding handed over on its own", () => {
916916

917917
it("keeps the pull request chip free of ask instructions when a fix and an ask share a draft", () => {
918918
const metadata = { ...base, state: "open" as const, isDraft: false };
919-
const ask = buildAskAboutPullRequestHandoff(metadata);
920-
for (const fix of [
921-
buildFixFindingHandoff({ ...metadata, finding: { kind: "thread", thread: reviewThread } }),
922-
buildFixFindingHandoff({
923-
...metadata,
924-
finding: {
925-
kind: "check",
926-
check: { name: "lint", status: "failure", description: null, url: null },
927-
},
928-
}),
929-
buildFixFindingHandoff({
930-
...metadata,
931-
finding: {
932-
kind: "comment",
933-
comment: {
934-
id: "review",
935-
kind: "review",
936-
reviewState: null,
937-
author: null,
938-
body: "fix it",
939-
createdAt: "2026-07-03T00:00:00Z",
940-
url: null,
941-
path: null,
942-
},
943-
},
944-
}),
945-
buildFixFindingsHandoff({
946-
...metadata,
947-
reviewThreads: [reviewThread],
948-
comments: [],
949-
checks: [],
950-
commentsTruncated: false,
951-
}),
952-
]) {
953-
for (const next of [
954-
appendHandoff(ask, fix),
955-
appendHandoff({ prompt: fix.prompt, reviewComments: [...fix.reviewComments] }, ask),
956-
]) {
957-
const contexts = next.reviewComments.filter((comment) => comment.pullRequest !== undefined);
958-
expect(contexts).toHaveLength(1);
959-
expect(contexts[0]?.text).not.toContain("Do not change any code");
960-
expect(contexts[0]?.pullRequest).toEqual(metadata);
919+
try {
920+
for (const initial of [false, true]) {
921+
setMergeRequestTerms(initial);
922+
const fixes = [
923+
buildFixFindingHandoff({
924+
...metadata,
925+
finding: { kind: "thread", thread: reviewThread },
926+
}),
927+
buildFixFindingHandoff({
928+
...metadata,
929+
finding: {
930+
kind: "check",
931+
check: { name: "lint", status: "failure", description: null, url: null },
932+
},
933+
}),
934+
buildFixFindingHandoff({
935+
...metadata,
936+
finding: {
937+
kind: "comment",
938+
comment: {
939+
id: "review",
940+
kind: "review",
941+
reviewState: null,
942+
author: null,
943+
body: "fix it",
944+
createdAt: "2026-07-03T00:00:00Z",
945+
url: null,
946+
path: null,
947+
},
948+
},
949+
}),
950+
buildFixFindingsHandoff({
951+
...metadata,
952+
reviewThreads: [reviewThread],
953+
comments: [],
954+
checks: [],
955+
commentsTruncated: false,
956+
}),
957+
];
958+
for (const selected of [false, true]) {
959+
setMergeRequestTerms(selected);
960+
const ask = buildAskAboutPullRequestHandoff(metadata);
961+
for (const fix of fixes) {
962+
for (const next of [
963+
appendHandoff(ask, fix),
964+
appendHandoff({ prompt: fix.prompt, reviewComments: [...fix.reviewComments] }, ask),
965+
]) {
966+
const contexts = next.reviewComments.filter(
967+
(comment) => comment.pullRequest !== undefined,
968+
);
969+
expect(contexts).toHaveLength(1);
970+
expect(contexts[0]?.text).not.toContain("Do not change any code");
971+
expect(contexts[0]?.pullRequest).toEqual(metadata);
972+
}
973+
}
974+
}
961975
}
976+
} finally {
977+
setMergeRequestTerms(false);
962978
}
963979
});
964980

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import { fromMarkdown } from "mdast-util-from-markdown";
1010
import {
1111
capitalizeTerm,
1212
currentChangeRequestTerms,
13+
MERGE_REQUEST_TERMINOLOGY,
14+
PULL_REQUEST_TERMINOLOGY,
1315
sourceControlClients,
1416
} from "@t3tools/client-runtime/source-control-clients";
1517
import * as Schema from "effect/Schema";
@@ -1192,13 +1194,14 @@ function pullRequestContextComment(
11921194
readonly isDraft: boolean;
11931195
},
11941196
instructions: ReadonlyArray<string>,
1197+
terms = currentChangeRequestTerms(),
11951198
): ReviewCommentContext {
1196-
const term = currentChangeRequestTerms().singular;
1199+
const term = terms.singular;
11971200
return {
11981201
// Use URLs because repositories can share pull request numbers.
11991202
id: `pull-request-context:${input.url}`,
12001203
sectionId: `pull-request:${input.number}`,
1201-
sectionTitle: `${currentChangeRequestTerms().shortLabel} #${input.number}`,
1204+
sectionTitle: `${terms.shortLabel} #${input.number}`,
12021205
filePath: `PR #${input.number}`,
12031206
startIndex: 0,
12041207
endIndex: 0,
@@ -1223,9 +1226,12 @@ function pullRequestContextComment(
12231226
}
12241227

12251228
function isPlainPullRequestContext(comment: ReviewCommentContext): boolean {
1229+
const metadata = comment.pullRequest;
12261230
return (
1227-
comment.pullRequest !== undefined &&
1228-
comment.text === pullRequestContextComment(comment.pullRequest, []).text
1231+
metadata !== undefined &&
1232+
[PULL_REQUEST_TERMINOLOGY, MERGE_REQUEST_TERMINOLOGY].some(
1233+
(terms) => comment.text === pullRequestContextComment(metadata, [], terms).text,
1234+
)
12291235
);
12301236
}
12311237

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { expect, it } from "vite-plus/test";
2+
import {
3+
MERGE_REQUEST_TERMINOLOGY,
4+
PULL_REQUEST_TERMINOLOGY,
5+
} from "@t3tools/client-runtime/source-control-clients";
6+
import { summarizePullRequestRouting } from "./PullRequestRoutingSettings.logic";
7+
8+
it("preserves environment names while formatting routing permissions", () => {
9+
for (const terms of [PULL_REQUEST_TERMINOLOGY, MERGE_REQUEST_TERMINOLOGY]) {
10+
expect(
11+
summarizePullRequestRouting(
12+
[
13+
{ label: "PR build machine", permission: "read" },
14+
{ label: "MR deploy machine", permission: "read-write" },
15+
{ label: "Pull request archive", permission: "off" },
16+
],
17+
terms,
18+
),
19+
).toBe(`MR deploy machine read and act \u00b7 PR build machine read ${terms.shortLabel}s`);
20+
expect(
21+
summarizePullRequestRouting([{ label: "PR build machine", permission: "off" }], terms),
22+
).toBeNull();
23+
}
24+
});
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import {
2+
currentChangeRequestTerms,
3+
formatChangeRequestText,
4+
} from "@t3tools/client-runtime/source-control-clients";
5+
import type { PullRequestRoutingPermission } from "@t3tools/client-runtime/connection";
6+
7+
const summaryLabels = { "read-write": "read and act", read: "read PRs" } as const;
8+
9+
export function summarizePullRequestRouting(
10+
entries: ReadonlyArray<{
11+
readonly label: string;
12+
readonly permission: PullRequestRoutingPermission;
13+
}>,
14+
terms = currentChangeRequestTerms(),
15+
): string | null {
16+
const groups = (["read-write", "read"] as const).flatMap((permission) => {
17+
const labels = entries.filter((entry) => entry.permission === permission);
18+
return labels.length === 0
19+
? []
20+
: [
21+
`${labels.map((entry) => entry.label).join(", ")} ${formatChangeRequestText(summaryLabels[permission], terms)}`,
22+
];
23+
});
24+
return groups.length === 0 ? null : groups.join(" \u00b7 ");
25+
}

‎apps/web/src/components/settings/PullRequestRoutingSettings.tsx‎

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,30 +17,14 @@ import { toastManager } from "../ui/toast";
1717
import { EnvironmentRow, EnvironmentTransportLabel } from "./EnvironmentRow";
1818
import { FoldedSettingsSection } from "./FoldedSettingsSection";
1919
import { searchableSetting } from "./settingsSearch";
20+
import { summarizePullRequestRouting } from "./PullRequestRoutingSettings.logic";
2021

2122
const options: ReadonlyArray<{ value: PullRequestRoutingPermission; label: string }> = [
2223
{ value: "off", label: "Off" },
2324
{ value: "read", label: "Read PRs" },
2425
{ value: "read-write", label: "Read and act" },
2526
];
2627

27-
const summaryLabels = { "read-write": "read and act", read: "read PRs" } as const;
28-
29-
function summarizePullRequestRouting(
30-
entries: ReadonlyArray<{
31-
readonly label: string;
32-
readonly permission: PullRequestRoutingPermission;
33-
}>,
34-
): string | null {
35-
const groups = (["read-write", "read"] as const).flatMap((permission) => {
36-
const labels = entries.filter((entry) => entry.permission === permission);
37-
return labels.length === 0
38-
? []
39-
: [`${labels.map((entry) => entry.label).join(", ")} ${summaryLabels[permission]}`];
40-
});
41-
return groups.length === 0 ? null : groups.join(" · ");
42-
}
43-
4428
export function PullRequestRoutingSettings({
4529
environments,
4630
}: {
@@ -63,15 +47,15 @@ export function PullRequestRoutingSettings({
6347
<FoldedSettingsSection
6448
id={id}
6549
title={title}
66-
summary={formatChangeRequestText(
50+
summary={
6751
summarizePullRequestRouting(
6852
environments.map((environment) => ({
6953
label: environment.label,
7054
permission: pullRequestRoutingPermissionFor(environment.entry, permissions),
7155
})),
72-
) ?? "Off",
73-
requestTerms,
74-
)}
56+
requestTerms,
57+
) ?? "Off"
58+
}
7559
>
7660
<p className="px-3 py-2.5 text-xs text-muted-foreground sm:px-4">
7761
Machines you trust here can read {requestTerms.shortLabel} data through each other's source

0 commit comments

Comments
 (0)