Skip to content

Commit 305986a

Browse files
committed
fix(clients): normalize older GitLab action labels
1 parent 8e31712 commit 305986a

3 files changed

Lines changed: 72 additions & 57 deletions

File tree

‎packages/client-runtime/src/sourceControlClients.test.ts‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -405,9 +405,11 @@ describe("currentChangeRequestTerms", () => {
405405
const text =
406406
"Pull Request / Pull requests / pull request / pull requests / a PR / PRs / PR #42 / https://host/pull/42 / https://host/PR/42?q=PR / pullRequest";
407407
expect(formatChangeRequestText(text, PULL_REQUEST_TERMINOLOGY)).toBe(text);
408-
expect(formatChangeRequestText(text, MERGE_REQUEST_TERMINOLOGY)).toBe(
409-
"Merge Request / Merge requests / merge request / merge requests / an MR / MRs / MR #42 / https://host/pull/42 / https://host/PR/42?q=PR / pullRequest",
410-
);
408+
const mergeText =
409+
"Merge Request / Merge requests / merge request / merge requests / an MR / MRs / MR #42 / https://host/pull/42 / https://host/PR/42?q=PR / pullRequest";
410+
expect(formatChangeRequestText(text, MERGE_REQUEST_TERMINOLOGY)).toBe(mergeText);
411+
expect(formatChangeRequestText(mergeText, MERGE_REQUEST_TERMINOLOGY)).toBe(mergeText);
412+
expect(formatChangeRequestText(mergeText, PULL_REQUEST_TERMINOLOGY)).toBe(text);
411413
});
412414

413415
it("says pull request for every host until merge request terms are on", () => {

‎packages/client-runtime/src/sourceControlClients.ts‎

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import {
44
HostCredentialSettings,
55
readSourceControlHostSettings,
66
changeRequestTerms,
7-
PULL_REQUEST_TERMINOLOGY,
87
type SourceControlAppSignIn,
98
type SourceControlDefinition,
109
} from "@t3tools/source-control-core/shared/definition";
@@ -48,16 +47,15 @@ export function currentChangeRequestTerms(): ChangeRequestTerminology {
4847
}
4948

5049
export function formatChangeRequestText(text: string, terms = currentChangeRequestTerms()): string {
51-
if (terms === PULL_REQUEST_TERMINOLOGY) return text;
5250
return text.replace(
53-
/https?:\/\/[^\s<>"`]+|\ba PR\b|\bPRs?\b|\b[Pp]ull [Rr]equests?\b/gu,
51+
/https?:\/\/[^\s<>"`]+|\b(?:a PR|an MR)\b|\b(?:PR|MR)s?\b|\b(?:[Pp]ull|[Mm]erge) [Rr]equests?\b/gu,
5452
(match) => {
5553
if (match.startsWith("http")) return match;
56-
if (match === "a PR") return terms.shortLabelWithArticle;
57-
if (match === "PR") return terms.shortLabel;
58-
if (match === "PRs") return `${terms.shortLabel}s`;
54+
if (match === "a PR" || match === "an MR") return terms.shortLabelWithArticle;
55+
if (match === "PR" || match === "MR") return terms.shortLabel;
56+
if (match === "PRs" || match === "MRs") return `${terms.shortLabel}s`;
5957
const label = match.endsWith("s") ? terms.plural : terms.singular;
60-
if (match.startsWith("pull")) return label;
58+
if (match.startsWith("pull") || match.startsWith("merge")) return label;
6159
return match.includes("Request")
6260
? label.split(" ").map(capitalizeTerm).join(" ")
6361
: capitalizeTerm(label);

‎packages/client-runtime/src/state/vcsAction.test.ts‎

Lines changed: 62 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,12 @@ describe("vcsActionState", () => {
254254
try {
255255
for (const enabled of [false, true]) {
256256
setMergeRequestTerms(enabled);
257-
for (const label of ["Preparing PR...", "Generating PR content..."]) {
257+
for (const label of [
258+
"Preparing PR...",
259+
"Generating PR content...",
260+
"Preparing MR...",
261+
"Generating MR content...",
262+
]) {
258263
const prEvent = progress({
259264
...event,
260265
actionId: transportActionId,
@@ -263,63 +268,73 @@ describe("vcsActionState", () => {
263268
});
264269
expect(
265270
normalizeVcsActionProgressEvent(target, transportActionId, actionId, prEvent),
266-
).toEqual({ ...prEvent, actionId, label: enabled ? label.replace("PR", "MR") : label });
271+
).toEqual({
272+
...prEvent,
273+
actionId,
274+
label: label.replace(/PR|MR/gu, enabled ? "MR" : "PR"),
275+
});
267276
}
268-
const url = "https://git.example.test/PR/pull/12";
269-
const terminalResult: GitRunStackedActionResult = {
270-
...result,
271-
commit: { ...result.commit, subject: "Fix PR rendering" },
272-
pr: { status: "opened_existing", url, title: "Fix PR rendering" },
273-
toast: {
274-
title: "Opened PR #12",
275-
description: "Fix PR rendering",
276-
cta: { kind: "open_pr", label: "View PR", url },
277-
},
278-
};
279-
expect(
280-
normalizeVcsActionProgressEvent(target, transportActionId, actionId, {
281-
cwd,
282-
action,
283-
actionId: transportActionId,
284-
kind: "action_finished",
285-
result: terminalResult,
286-
}),
287-
).toEqual({
288-
cwd,
289-
action,
290-
actionId,
291-
kind: "action_finished",
292-
result: {
293-
...terminalResult,
277+
for (const sourceTerm of ["PR", "MR"]) {
278+
const url = `https://git.example.test/${sourceTerm}/pull/12`;
279+
const terminalResult: GitRunStackedActionResult = {
280+
...result,
281+
commit: { ...result.commit, subject: `Fix ${sourceTerm} rendering` },
282+
pr: { status: "opened_existing", url, title: `Fix ${sourceTerm} rendering` },
294283
toast: {
295-
...terminalResult.toast,
296-
title: enabled ? "Opened MR #12" : "Opened PR #12",
297-
cta: { kind: "open_pr", label: enabled ? "View MR" : "View PR", url },
284+
title: `Opened ${sourceTerm} #12`,
285+
description: `Fix ${sourceTerm} rendering`,
286+
cta: { kind: "open_pr", label: `View ${sourceTerm}`, url },
298287
},
299-
},
300-
});
301-
expect(
302-
normalizeVcsActionProgressEvent(target, transportActionId, actionId, {
288+
};
289+
expect(
290+
normalizeVcsActionProgressEvent(target, transportActionId, actionId, {
291+
cwd,
292+
action,
293+
actionId: transportActionId,
294+
kind: "action_finished",
295+
result: terminalResult,
296+
}),
297+
).toEqual({
303298
cwd,
304299
action,
305-
actionId: transportActionId,
300+
actionId,
306301
kind: "action_finished",
307302
result: {
308-
...result,
303+
...terminalResult,
309304
toast: {
310-
title: "Pushed to feature/PR",
311-
cta: { kind: "run_action", label: "Create PR", action: { kind: "create_pr" } },
305+
...terminalResult.toast,
306+
title: enabled ? "Opened MR #12" : "Opened PR #12",
307+
cta: { kind: "open_pr", label: enabled ? "View MR" : "View PR", url },
312308
},
313309
},
314-
}),
315-
).toMatchObject({
316-
result: {
317-
toast: {
318-
title: "Pushed to feature/PR",
319-
cta: { label: enabled ? "Create MR" : "Create PR" },
310+
});
311+
expect(
312+
normalizeVcsActionProgressEvent(target, transportActionId, actionId, {
313+
cwd,
314+
action,
315+
actionId: transportActionId,
316+
kind: "action_finished",
317+
result: {
318+
...result,
319+
toast: {
320+
title: `Pushed to feature/${sourceTerm}`,
321+
cta: {
322+
kind: "run_action",
323+
label: `Create ${sourceTerm}`,
324+
action: { kind: "create_pr" },
325+
},
326+
},
327+
},
328+
}),
329+
).toMatchObject({
330+
result: {
331+
toast: {
332+
title: `Pushed to feature/${sourceTerm}`,
333+
cta: { label: enabled ? "Create MR" : "Create PR" },
334+
},
320335
},
321-
},
322-
});
336+
});
337+
}
323338
}
324339
} finally {
325340
setMergeRequestTerms(false);

0 commit comments

Comments
 (0)