Skip to content

Commit 510df58

Browse files
committed
fix(source-control): preserve explicit ports in pull request links
1 parent 05c0ed7 commit 510df58

3 files changed

Lines changed: 29 additions & 0 deletions

File tree

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,7 @@ export function parseChangeRequestPath(url: URL, route: RegExp): ParsedChangeReq
404404
repository: repository.toLowerCase(),
405405
number,
406406
repositoryUrl: `${url.origin}/${repository}`,
407+
...(url.port ? { authority: url.host.toLowerCase() } : {}),
407408
}
408409
: null;
409410
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ describe("GitHub change request URLs", () => {
1515
});
1616
expect(parse("https://GHE.Example.com:8443/acme/web/pull/42/")).toEqual({
1717
host: "ghe.example.com",
18+
authority: "ghe.example.com:8443",
1819
repository: "acme/web",
1920
number: 42,
2021
repositoryUrl: "https://ghe.example.com:8443/acme/web",

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { ChangeRequestProjectIdentity } from "@t3tools/source-control-core/shared/definition";
12
import { recognizeRemoteWith } from "@t3tools/source-control-core/shared/definition";
23
import { describe, expect, it } from "vite-plus/test";
34

@@ -20,6 +21,32 @@ describe("GitLab change request URLs", () => {
2021
});
2122
});
2223

24+
it("matches a merge request's explicit HTTP port before choosing a project", () => {
25+
const link = parse("https://gitlab.example.test:9443/team/project/-/merge_requests/9")!;
26+
const identity = (remoteUrl: string): ChangeRequestProjectIdentity => ({
27+
canonicalKey: "gitlab.example.test/team/project",
28+
displayName: "team/project",
29+
locator: { source: "git-remote", remoteName: "origin", remoteUrl },
30+
});
31+
const matching = identity("https://gitlab.example.test:9443/team/project.git");
32+
expect(definition.isChangeRequestInRepository(matching, link)).toBe(true);
33+
expect(definition.canReadChangeRequestOnHost(matching, link)).toBe(true);
34+
for (const remote of [
35+
"https://gitlab.example.test:8443/team/project.git",
36+
"https://gitlab.example.test/team/project.git",
37+
]) {
38+
expect(definition.isChangeRequestInRepository(identity(remote), link), remote).toBe(false);
39+
expect(definition.canReadChangeRequestOnHost(identity(remote), link), remote).toBe(false);
40+
}
41+
expect(link).toMatchObject({
42+
host: "gitlab.example.test",
43+
authority: "gitlab.example.test:9443",
44+
repositoryUrl: "https://gitlab.example.test:9443/team/project",
45+
});
46+
const ssh = identity("ssh://[email protected]:2222/team/project.git");
47+
expect(definition.isChangeRequestInRepository(ssh, link)).toBe(true);
48+
});
49+
2350
it("keeps pull-like segments inside nested repository paths", () => {
2451
expect(
2552
parse("https://gitlab.example.test/group/pull/123/repo/-/merge_requests/42")?.repositoryUrl,

0 commit comments

Comments
 (0)