Skip to content

Commit 505d022

Browse files
only21milclaudemaria-rcks
authored
fix(gitlab): accept merge request URLs from self-hosted hosts (pingdotgg#23848)
Co-authored-by: Claude Opus 5.5 <[email protected]> Co-authored-by: maria-rcks <[email protected]>
1 parent 69310db commit 505d022

3 files changed

Lines changed: 30 additions & 1 deletion

File tree

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,13 @@ describe("parsePullRequestReference", () => {
161161
).toBe("https://acme.visualstudio.com/project/_git/t3code/pullrequest/42");
162162
});
163163

164+
it.each([
165+
"https://code.example.com/group/project/-/merge_requests/42",
166+
"http://git.internal/group/sub/project/-/merge_requests/7",
167+
])("accepts self-hosted GitLab merge request URL %s", (url) => {
168+
expect(parsePullRequestReference(url)).toBe(url);
169+
});
170+
164171
it("accepts gh pr checkout commands with raw numbers", () => {
165172
expect(parsePullRequestReference("gh pr checkout 42")).toBe("42");
166173
});

‎packages/source-control-gitlab/src/shared/definition.test.ts‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,28 @@ describe("GitLab change request URLs", () => {
3131
expect(parse("https://gitlab.com/t3code/-/merge_requests/12")).toBeNull();
3232
});
3333

34+
it("recognizes only merge request URLs it can parse", () => {
35+
for (const url of [
36+
"https://gitlab.com/g/p?x=/-/merge_requests/5",
37+
"https://gitlab.com/g/p#/-/merge_requests/5",
38+
"https://gitlab.com?x=/g/p/-/merge_requests/5",
39+
"https://gitlab.com#/g/p/-/merge_requests/5",
40+
"https://gitlab.com/t3code/-/merge_requests/12",
41+
"https://gitlab.com/g//-/merge_requests/5",
42+
]) {
43+
expect(definition.isChangeRequestReference(url), url).toBe(false);
44+
expect(parse(url), url).toBeNull();
45+
}
46+
for (const url of [
47+
"https://code.acme.test/a/b/c/-/merge_requests/7?tab=diffs",
48+
"http://git.internal/a/b/c/-/merge_requests/7#note_1",
49+
"https://code.acme.test/a/b/c/-/merge_requests/7/diffs",
50+
]) {
51+
expect(definition.isChangeRequestReference(url), url).toBe(true);
52+
expect(parse(url), url).toMatchObject({ repository: "a/b/c", number: 7 });
53+
}
54+
});
55+
3456
it("builds merge request URLs below the repository", () => {
3557
expect(
3658
definition.changeRequestUrl({

‎packages/source-control-gitlab/src/shared/definition.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { icon } from "./icon.ts";
1111

1212
const CHECKOUT_COMMAND = /^glab\s+mr\s+checkout\s+(.+)$/i;
1313
const CHANGE_REQUEST_REFERENCE =
14-
/^https:\/\/[^/\s]*gitlab[^/\s]*\/.+\/-\/merge_requests\/(\d+)(?:[/?#].*)?$/i;
14+
/^https?:\/\/[^/?#\s]+\/[^/?#\s]+(?:\/[^/?#\s]+)+\/-\/merge_requests\/(\d+)(?:[/?#].*)?$/i;
1515

1616
// Self-managed GitLab runs on any hostname and nests projects in groups.
1717
const CHANGE_REQUEST_PATH = /^\/([^/]+(?:\/[^/]+)+)\/-\/merge_requests\/(\d+)(?:\/|$)/u;

0 commit comments

Comments
 (0)