From c3d203903a98ef1268a5249253f7951218fc81c0 Mon Sep 17 00:00:00 2001 From: SAPHID Date: Tue, 1 Dec 2026 06:31:20 +0000 Subject: [PATCH 1/2] fix(source-control): route nested GitLab merge requests before GitHub prefix matches --- .../src/changeRequestLinks.test.ts | 39 +++++++++++++++++++ .../src/registry.ts | 4 +- 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/packages/client-runtime/src/changeRequestLinks.test.ts b/packages/client-runtime/src/changeRequestLinks.test.ts index 5dd624b74ae26..dbdd2ac062637 100644 --- a/packages/client-runtime/src/changeRequestLinks.test.ts +++ b/packages/client-runtime/src/changeRequestLinks.test.ts @@ -173,6 +173,45 @@ describe("resolveChangeRequestLinkTarget", () => { }), ).toBeNull(); }); + + it("reads a nested GitLab merge request whose path also looks like a GitHub pull request", () => { + for (const host of ["gitlab.com", "forge.example"]) { + const gitlab = { + ...project("gitlab", local, `${host}/acme/team/pull/123`), + repositoryIdentity: { + canonicalKey: `${host}/acme/team/pull/123`, + provider: SourceControlProviderKind.make("gitlab"), + displayName: "acme/team/pull/123", + locator: { + source: "git-remote", + remoteName: "origin", + remoteUrl: `https://${host}/acme/team/pull/123.git`, + }, + } satisfies RepositoryIdentity, + }; + expect( + resolveChangeRequestLinkTarget({ + url: `https://${host}/acme/team/pull/123/-/merge_requests/7`, + projects: [gitlab], + configLoaded: loaded, + environmentId: local, + lendHostProject: false, + }), + ).toEqual({ project: gitlab, host, repository: "acme/team/pull/123", number: 7 }); + } + }); + + it("still reads a GitHub pull request subpage as GitHub's", () => { + expect( + resolveChangeRequestLinkTarget({ + url: "https://github.com/acme/app/pull/7/files", + projects, + configLoaded: loaded, + environmentId: remote, + lendHostProject: false, + }), + ).toEqual({ project: elsewhere, host: "github.com", repository: "acme/app", number: 7 }); + }); }); describe("resolvePullRequestPreviewTarget", () => { diff --git a/packages/source-control-definitions/src/registry.ts b/packages/source-control-definitions/src/registry.ts index 90f14961c0d57..38858598e5af7 100644 --- a/packages/source-control-definitions/src/registry.ts +++ b/packages/source-control-definitions/src/registry.ts @@ -12,7 +12,8 @@ export { canonicalizePullRequestUrl as canonicalizeGitCafePullRequestUrl } from /** * GitHub comes first as the client default for unknown hosts. GitCafe, TanStack Source and Origin - * claim URLs first: GitHub and Forgejo accept the same routes on any hostname. TanStack Source is a + * claim URLs first: GitHub and Forgejo accept the same routes on any hostname. GitLab's `/-/` routes + * claim before GitHub's, which a nested project path can also match. TanStack Source is a * private beta: every reader knows its URLs, and only a server with its flag on offers the forge. */ export const builtInSourceControlDefinitions = makeSourceControlDefinitionRegistry( @@ -32,6 +33,7 @@ export const builtInSourceControlDefinitions = makeSourceControlDefinitionRegist TanStackSource.definition.kind, CursorOrigin.definition.kind, AzureDevOps.definition.kind, + GitLab.definition.kind, ], recognizeRemotesIn: [ GitCafe.definition.kind, From fac210a5ad2b8a7a7cb7adabe3fc6f35ab7483f6 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Tue, 1 Dec 2026 06:52:22 +0000 Subject: [PATCH 2/2] test(source-control): pin nested GitLab merge request routing in the registry Move the regression check to the registry parse tests, where the claim order lives, and drop the GitHub subpage case those tests already cover. Co-Authored-By: Claude Opus 5.5 --- .../src/changeRequestLinks.test.ts | 39 ------------------- .../src/sourceControlClients.test.ts | 7 ++++ 2 files changed, 7 insertions(+), 39 deletions(-) diff --git a/packages/client-runtime/src/changeRequestLinks.test.ts b/packages/client-runtime/src/changeRequestLinks.test.ts index dbdd2ac062637..5dd624b74ae26 100644 --- a/packages/client-runtime/src/changeRequestLinks.test.ts +++ b/packages/client-runtime/src/changeRequestLinks.test.ts @@ -173,45 +173,6 @@ describe("resolveChangeRequestLinkTarget", () => { }), ).toBeNull(); }); - - it("reads a nested GitLab merge request whose path also looks like a GitHub pull request", () => { - for (const host of ["gitlab.com", "forge.example"]) { - const gitlab = { - ...project("gitlab", local, `${host}/acme/team/pull/123`), - repositoryIdentity: { - canonicalKey: `${host}/acme/team/pull/123`, - provider: SourceControlProviderKind.make("gitlab"), - displayName: "acme/team/pull/123", - locator: { - source: "git-remote", - remoteName: "origin", - remoteUrl: `https://${host}/acme/team/pull/123.git`, - }, - } satisfies RepositoryIdentity, - }; - expect( - resolveChangeRequestLinkTarget({ - url: `https://${host}/acme/team/pull/123/-/merge_requests/7`, - projects: [gitlab], - configLoaded: loaded, - environmentId: local, - lendHostProject: false, - }), - ).toEqual({ project: gitlab, host, repository: "acme/team/pull/123", number: 7 }); - } - }); - - it("still reads a GitHub pull request subpage as GitHub's", () => { - expect( - resolveChangeRequestLinkTarget({ - url: "https://github.com/acme/app/pull/7/files", - projects, - configLoaded: loaded, - environmentId: remote, - lendHostProject: false, - }), - ).toEqual({ project: elsewhere, host: "github.com", repository: "acme/app", number: 7 }); - }); }); describe("resolvePullRequestPreviewTarget", () => { diff --git a/packages/client-runtime/src/sourceControlClients.test.ts b/packages/client-runtime/src/sourceControlClients.test.ts index 1f2cbfbc3a4d7..9ac93156147e2 100644 --- a/packages/client-runtime/src/sourceControlClients.test.ts +++ b/packages/client-runtime/src/sourceControlClients.test.ts @@ -106,6 +106,13 @@ describe("sourceControlClients.parseChangeRequestUrl", () => { repository: "team/project", number: 9, }); + const nested = "https://forge.example/acme/team/pull/123/-/merge_requests/7"; + expect(parse(nested)).toEqual({ + host: "forge.example", + repository: "acme/team/pull/123", + number: 7, + }); + expect(kindOf(nested)).toBe("gitlab"); expect( sourceControlClients.changeRequestUrlFromReferenceAutolink( "https://gitlab.com/team/apps/web/-/merge_requests/42",