The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 23, 01:45 UTC
fix(shared): recognise Azure DevOps Server pull request links (#14626)
Co-authored-by: Julius Marminge <julius0216@outlook.com>
Leonel Rivas committed
Oct 19, 2026 at 13:23 UTC
fa68107b8b318b0f0d818bd410100a3a5e9c2c70
5 files changed
+143
-46
apps/server/src/mcp/toolkits/pullRequests/handlers.test.ts
+38
@@ -426,6 +426,44 @@ describe("pull request toolkit handlers", () => {
426
}),
427
);
428
429
+ it.effect("links Azure DevOps Server URLs and numeric references without a known provider", () =>
430
+ Effect.gen(function* () {
431
+ const harness = yield* makeHarness({
432
+ project: makeProject({
433
+ canonicalKey: "scm.example.test/tfs/collection/project/_git/repo",
434
+ locator: {
435
+ source: "git-remote",
436
+ remoteName: "origin",
437
+ remoteUrl: "http://dummy:secret@scm.example.test:8080/tfs/Collection/Project/_git/Repo",
438
+ },
439
+ provider: "unknown",
440
+ displayName: "tfs/collection/project/_git/repo",
441
+ }),
442
+ });
443
+ const generated =
444
+ "http://scm.example.test:8080/tfs/collection/project/_git/repo/pullrequest/124";
445
+ const fromNumber = yield* harness.call("link_pull_request", {
446
+ repository: "tfs/Collection/Project/_git/Repo",
447
+ number: 124,
448
+ });
449
+ expect.soft(fromNumber.url).toBe(generated);
450
+
451
+ const supplied = "https://scm.example.test/tfs/Collection/Project/_git/Repo/pullrequest/123";
452
+ const fromUrl = yield* harness.call("link_pull_request", { url: supplied });
453
+ expect(fromUrl).toEqual({
454
+ host: "scm.example.test",
455
+ repository: "tfs/collection/project/_git/repo",
456
+ number: 123,
457
+ url: supplied,
458
+ alreadyLinked: false,
459
+ });
460
+ expect(yield* Ref.get(harness.commands)).toMatchObject([
461
+ { type: "thread.pull-request.link", number: 124, url: generated },
462
+ { type: "thread.pull-request.link", number: 123, url: supplied },
463
+ ]);
464
+ }),
465
+ );
466
+
467
it.effect("rejects a target that names neither a URL nor repository and number", () =>
468
Effect.gen(function* () {
469
const harness = yield* makeHarness();
apps/server/src/mcp/toolkits/pullRequests/handlers.ts
+11
-1
@@ -97,7 +97,17 @@ const resolveTarget = Effect.fn("PullRequestsToolkit.resolveTarget")(function* (
97
repository,
98
input.number,
99
project?.repositoryIdentity?.locator.remoteUrl,
100
- ) ?? `https://${host}/${repository}/pull/${input.number}`;
100
+ ) ??
101
+ (/(?:^|\/)_git\/[^/]+$/u.test(repository)
102
+ ? changeRequestUrlFor(
103
+ "azure-devops",
104
+ host,
105
+ repository,
106
+ input.number,
107
+ project?.repositoryIdentity?.locator.remoteUrl,
108
+ )
109
+ : null) ??
110
+ `https://${host}/${repository}/pull/${input.number}`;
111
return {
112
...normalizeThreadPullRequestKey({ host, repository, number: input.number, url }),
113
url,
apps/web/src/lib/openPullRequestLink.test.ts
+15
-8
@@ -249,17 +249,24 @@ describe("findProjectOnChangeRequestHost", () => {
249
});
250
251
it.each([
252
- "ssh.dev.azure.com/v3/org-a/project/web",
253
- "vs-ssh.visualstudio.com/v3/org-a/project/web",
254
- "org-a.visualstudio.com/defaultcollection/project/_git/web",
255
- "dev.azure.com/org-a/project/_git/web",
256
- ])("matches Azure browser references against %s", (canonicalKey) => {
252
+ ["ssh.dev.azure.com/v3/org-a/project/web", "git@ssh.dev.azure.com:v3/org-a/project/web"],
253
+ [
254
+ "vs-ssh.visualstudio.com/v3/org-a/project/web",
255
+ "git@vs-ssh.visualstudio.com:v3/org-a/project/web",
256
+ ],
257
+ [
258
+ "org-a.visualstudio.com/defaultcollection/project/_git/web",
259
+ "https://org-a.visualstudio.com/DefaultCollection/Project/_git/Web",
260
+ ],
261
+ ["dev.azure.com/org-a/project/_git/web", "https://org-a@dev.azure.com/org-a/Project/_git/Web"],
262
+ ])("matches Azure browser references against %s", (canonicalKey, remoteUrl) => {
263
const checkout = project("azure", {
258
- canonicalKey,
259
- provider: "azure-devops",
264
+ ...repositoryIdentity("azure-devops", canonicalKey, remoteUrl),
265
displayName: canonicalKey.split("/").slice(1).join("/"),
266
});
262
- const reference = { host: "dev.azure.com", repository: "org-a/project/_git/web", number: 42 };
267
+ const reference = parseChangeRequestUrl(
268
+ "https://dev.azure.com/org-a/project/_git/web/pullrequest/42",
269
+ )!;
270
expect(findProjectForChangeRequest([checkout], reference)).toBe(checkout);
271
expect(findProjectOnChangeRequestHost([checkout], reference)).toBe(checkout);
272
expect(
packages/shared/src/changeRequestUrl.test.ts
+35
@@ -1,11 +1,14 @@
1
+import { ProjectId } from "@t3tools/contracts";
2
import { describe, expect, it } from "vite-plus/test";
3
4
import {
5
changeRequestUrlFor,
6
+ matchesLinkedPullRequestUrl,
7
parseChangeRequestUrl,
8
pullRequestCandidateUrlFromReferenceAutolink,
9
siblingPullRequestUrl,
10
} from "./changeRequestUrl.ts";
11
+import { normalizeThreadPullRequestKey } from "./threadPullRequests.ts";
12
13
describe("parseChangeRequestUrl", () => {
14
it("reads a GitHub pull request, lower-casing the repository", () => {
@@ -69,6 +72,32 @@ describe("parseChangeRequestUrl", () => {
72
).toEqual({ host: "acme.visualstudio.com", repository: "platform/_git/t3code", number: 17 });
73
});
74
75
+ it("reads Azure DevOps Server links and keeps servers on different ports distinct", () => {
76
+ for (const host of ["scm.example.test", "git.cafe", "code.bitbucket.example.test"]) {
77
+ const repository = "tfs/collection/project/_git/repo";
78
+ const linked = {
79
+ projectId: ProjectId.make("project-1"),
80
+ host,
81
+ repository,
82
+ number: 123,
83
+ url: `https://${host.toUpperCase()}:8443/tfs/Collection/Project/_git/Repo/pullrequest/123`,
84
+ };
85
+ const other = { ...linked, url: linked.url.replace(":8443/", ":9443/") };
86
+ expect.soft(parseChangeRequestUrl(linked.url), host).toEqual({
87
+ host,
88
+ authority: `${host}:8443`,
89
+ repository,
90
+ number: 123,
91
+ });
92
+ expect.soft(matchesLinkedPullRequestUrl(linked, `${linked.url}?view=files`), host).toBe(true);
93
+ expect.soft(matchesLinkedPullRequestUrl(linked, other.url), host).toBe(false);
94
+ expect.soft([linked, other].map(normalizeThreadPullRequestKey), host).toEqual([
95
+ { host: `${host}:8443`, repository, number: 123 },
96
+ { host: `${host}:9443`, repository, number: 123 },
97
+ ]);
98
+ }
99
+ });
100
+
101
it("survives trailing segments, a trailing slash and a query string", () => {
102
expect(parseChangeRequestUrl("https://github.com/t3tools/t3code/pull/123/files?w=1")).toEqual({
103
host: "github.com",
@@ -90,6 +119,12 @@ describe("parseChangeRequestUrl", () => {
119
"https://github.com/t3tools/t3code/pull/abc",
120
"https://gitlab.com/t3tools/t3code/-/issues/12",
121
"https://blog.example.test/2026/updates/pull/3",
122
+ "https://scm.example.test/tfs/Collection/Project/_git/Repo",
123
+ "https://scm.example.test/tfs/Collection/Project/pullrequest/123",
124
+ "https://scm.example.test/tfs/Collection/Project/_git/Repo/pullrequest/abc",
125
+ "https://scm.example.test/tfs/Collection/Project/_git/Repo/pullrequest/0",
126
+ "https://scm.example.test/tfs/Collection/Project/_git/Repo/pullrequest/9007199254740992",
127
+ "ftp://scm.example.test/tfs/Collection/Project/_git/Repo/pullrequest/123",
128
"javascript:alert(1)//github.com/t3tools/t3code/pull/1",
129
"not a url",
130
]) {
packages/shared/src/changeRequestUrl.ts
+44
-37
@@ -30,28 +30,28 @@ export function parseChangeRequestUrl(targetUrl: string): ChangeRequestLink | nu
30
31
if (host === "git.cafe" || host === "staging.git.cafe") {
32
const match = /^\/([^/]+\/[^/]+)\/pulls\/(\d+)(?:\/|$)/u.exec(url.pathname);
33
- return claim(host, match);
34
- }
35
- if (isHostOf(host, "github.com", "github")) {
36
- const match = /^\/([^/]+\/[^/]+)\/pull\/(\d+)(?:\/|$)/u.exec(url.pathname);
33
if (match) return claim(host, match);
34
+ } else {
35
+ if (isHostOf(host, "github.com", "github")) {
36
+ const match = /^\/([^/]+\/[^/]+)\/pull\/(\d+)(?:\/|$)/u.exec(url.pathname);
37
+ if (match) return claim(host, match);
38
+ }
39
+ const forgejo = /^\/([^/]+(?:\/[^/]+)+)\/pulls\/(\d+)(?:\/|$)/u.exec(url.pathname);
40
+ if (forgejo) {
41
+ const link = claim(host, forgejo);
42
+ return link === null ? null : { ...link, authority: url.host.toLowerCase() };
43
+ }
44
+ const gitlab = /^\/([^/]+(?:\/[^/]+)+)\/-\/merge_requests\/(\d+)(?:\/|$)/u.exec(url.pathname);
45
+ if (gitlab) return claim(host, gitlab);
46
+ if (isHostOf(host, "bitbucket.org", "bitbucket")) {
47
+ const match = /^\/([^/]+\/[^/]+)\/pull-requests\/(\d+)(?:\/|$)/u.exec(url.pathname);
48
+ if (match) return claim(host, match);
49
+ }
50
}
39
- const forgejo = /^\/([^/]+(?:\/[^/]+)+)\/pulls\/(\d+)(?:\/|$)/u.exec(url.pathname);
40
- if (forgejo) {
41
- const link = claim(host, forgejo);
42
- return link === null ? null : { ...link, authority: url.host.toLowerCase() };
43
- }
44
- const gitlab = /^\/([^/]+(?:\/[^/]+)+)\/-\/merge_requests\/(\d+)(?:\/|$)/u.exec(url.pathname);
45
- if (gitlab) return claim(host, gitlab);
46
- if (isHostOf(host, "bitbucket.org", "bitbucket")) {
47
- const match = /^\/([^/]+\/[^/]+)\/pull-requests\/(\d+)(?:\/|$)/u.exec(url.pathname);
48
- return claim(host, match);
49
- }
50
- if (isHostOf(host, "dev.azure.com") || host.endsWith(".visualstudio.com")) {
51
- const match = /^\/((?:[^/]+\/)*_git\/[^/]+)\/pullrequest\/(\d+)(?:\/|$)/u.exec(url.pathname);
52
- return claim(host, match);
53
- }
54
- return null;
51
+ // Azure DevOps Server can use any hostname; its `_git` pull request route identifies it.
52
+ const azure = /^\/((?:[^/]+\/)*_git\/[^/]+)\/pullrequest\/(\d+)(?:\/|$)/u.exec(url.pathname);
53
+ const link = claim(host, azure);
54
+ return link === null || url.port === "" ? link : { ...link, authority: url.host.toLowerCase() };
55
}
56
57
function claim(host: string, match: RegExpExecArray | null): ChangeRequestLink | null {
@@ -62,6 +62,22 @@ function claim(host: string, match: RegExpExecArray | null): ChangeRequestLink |
62
: null;
63
}
64
65
+function remoteWebOrigin(host: string, remoteUrl: string | undefined): string {
66
+ try {
67
+ const remote = new URL(remoteUrl ?? "");
68
+ if (
69
+ (remote.protocol === "http:" || remote.protocol === "https:") &&
70
+ (remote.hostname.toLowerCase() === host.toLowerCase() ||
71
+ remote.host.toLowerCase() === host.toLowerCase())
72
+ ) {
73
+ return remote.origin;
74
+ }
75
+ } catch {
76
+ // SSH remotes do not specify the server's web origin.
77
+ }
78
+ return `https://${host}`;
79
+}
80
+
81
export function changeRequestUrlFor(
82
kind: string | null | undefined,
83
host: string,
@@ -74,27 +90,18 @@ export function changeRequestUrlFor(
90
return `https://${host}/${repository}/pull/${number}`;
91
case "gitcafe":
92
return `https://${host}/${repository}/pulls/${number}`;
77
- case "forgejo": {
78
- try {
79
- const remote = new URL(remoteUrl ?? "");
80
- if (
81
- (remote.protocol === "http:" || remote.protocol === "https:") &&
82
- (remote.hostname.toLowerCase() === host.toLowerCase() ||
83
- remote.host.toLowerCase() === host.toLowerCase())
84
- ) {
85
- return `${remote.origin}/${repository}/pulls/${number}`;
86
- }
87
- } catch {
88
- // SSH remotes do not specify the server's web origin.
89
- }
90
- return `https://${host}/${repository}/pulls/${number}`;
91
- }
93
+ case "forgejo":
94
+ return `${remoteWebOrigin(host, remoteUrl)}/${repository}/pulls/${number}`;
95
case "gitlab":
96
return `https://${host}/${repository}/-/merge_requests/${number}`;
97
case "bitbucket":
98
return `https://${host}/${repository}/pull-requests/${number}`;
96
- case "azure-devops":
97
- return `https://${canonicalRepositoryKey(`${host}/${repository}`.toLowerCase())}/pullrequest/${number}`;
99
+ case "azure-devops": {
100
+ const [canonicalHost = host, ...path] = canonicalRepositoryKey(
101
+ `${host}/${repository}`.toLowerCase(),
102
+ ).split("/");
103
+ return `${remoteWebOrigin(canonicalHost, remoteUrl)}/${path.join("/")}/pullrequest/${number}`;
104
+ }
105
default:
106
return null;
107
}