Skip to content

Commit 0673c02

Browse files
committed
fix(shared): recognise Azure DevOps Server pull request links
1 parent 5cc99e1 commit 0673c02

4 files changed

Lines changed: 60 additions & 10 deletions

File tree

‎apps/server/src/mcp/toolkits/pullRequests/handlers.test.ts‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,38 @@ describe("pull request toolkit handlers", () => {
299299
}),
300300
);
301301

302+
it.effect("links an Azure DevOps Server pull request on a host it has no provider for", () =>
303+
Effect.gen(function* () {
304+
const harness = yield* makeHarness({
305+
project: makeProject({
306+
canonicalKey: "scm.example.com/tfs/collection/project/_git/repo",
307+
locator: {
308+
source: "git-remote",
309+
remoteName: "origin",
310+
remoteUrl: "https://scm.example.com/tfs/Collection/Project/_git/Repo",
311+
},
312+
provider: "unknown",
313+
displayName: "tfs/collection/project/_git/repo",
314+
}),
315+
});
316+
const supplied = "https://scm.example.com/tfs/Collection/Project/_git/Repo/pullrequest/123";
317+
const fromUrl = yield* harness.call("link_pull_request", { url: supplied });
318+
expect(fromUrl).toMatchObject({
319+
host: "scm.example.com",
320+
repository: "tfs/collection/project/_git/repo",
321+
number: 123,
322+
url: supplied,
323+
});
324+
const fromNumber = yield* harness.call("link_pull_request", {
325+
repository: "tfs/Collection/Project/_git/Repo",
326+
number: 124,
327+
});
328+
expect(fromNumber.url).toBe(
329+
"https://scm.example.com/tfs/collection/project/_git/repo/pullrequest/124",
330+
);
331+
}),
332+
);
333+
302334
it.effect("rejects a target that names neither a URL nor repository and number", () =>
303335
Effect.gen(function* () {
304336
const harness = yield* makeHarness();

‎apps/server/src/mcp/toolkits/pullRequests/handlers.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,12 @@ const resolveTarget = Effect.fn("PullRequestsToolkit.resolveTarget")(function* (
9191
repository,
9292
input.number,
9393
project?.repositoryIdentity?.locator.remoteUrl,
94-
) ?? `https://${host}/${repository}/pull/${input.number}`;
94+
) ??
95+
// An Azure DevOps repository path keeps its `_git` segment on any host, Server included.
96+
(/(?:^|\/)_git\//u.test(repository)
97+
? changeRequestUrlFor("azure-devops", host, repository, input.number)
98+
: null) ??
99+
`https://${host}/${repository}/pull/${input.number}`;
95100
return {
96101
...normalizeThreadPullRequestKey({ host, repository, number: input.number, url }),
97102
url,

‎packages/shared/src/changeRequestUrl.test.ts‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,18 @@ describe("parseChangeRequestUrl", () => {
6969
).toEqual({ host: "acme.visualstudio.com", repository: "platform/_git/t3code", number: 17 });
7070
});
7171

72+
it("reads an Azure DevOps Server pull request on its own domain, collection path included", () => {
73+
expect(
74+
parseChangeRequestUrl(
75+
"https://scm.example.com/tfs/Collection/Project/_git/Repo/pullrequest/123",
76+
),
77+
).toEqual({
78+
host: "scm.example.com",
79+
repository: "tfs/collection/project/_git/repo",
80+
number: 123,
81+
});
82+
});
83+
7284
it("survives trailing segments, a trailing slash and a query string", () => {
7385
expect(parseChangeRequestUrl("https://github.com/t3tools/t3code/pull/123/files?w=1")).toEqual({
7486
host: "github.com",
@@ -90,6 +102,9 @@ describe("parseChangeRequestUrl", () => {
90102
"https://github.com/t3tools/t3code/pull/abc",
91103
"https://gitlab.com/t3tools/t3code/-/issues/12",
92104
"https://blog.example.test/2026/updates/pull/3",
105+
"https://scm.example.com/tfs/Collection/Project/_git/Repo",
106+
"https://scm.example.com/tfs/Collection/Project/_git/Repo/pullrequest/abc",
107+
"https://scm.example.com/tfs/Collection/Project/pullrequest/123",
93108
"javascript:alert(1)//github.com/t3tools/t3code/pull/1",
94109
"not a url",
95110
]) {

‎packages/shared/src/changeRequestUrl.ts‎

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ function isHostOf(hostname: string, apex: string, label?: string): boolean {
3030
*
3131
* Each host is recognised by the path shape it alone uses, guarded by a hostname it could
3232
* plausibly be served from, since self-hosted installs are named whatever their admin chose:
33-
* GitLab's `/-/` marker is unique enough to trust on any hostname, while `/pull/` is generic
34-
* enough that it is only believed from a GitHub-ish host.
33+
* GitLab's `/-/` marker and Azure DevOps' `/_git/…/pullrequest/` are unique enough to trust on
34+
* any hostname, while `/pull/` is generic enough that it is only believed from a GitHub-ish host.
3535
*
3636
* Nothing here tries to tell a lookalike hostname from a real one — `github.com.evil.test` and
3737
* the rest are an open set, and blocking spellings of it costs real hosts (`gitlab.com.br` is a
@@ -68,13 +68,11 @@ export function parseChangeRequestUrl(targetUrl: string): ChangeRequestLink | nu
6868
const match = /^\/([^/]+\/[^/]+)\/pull-requests\/(\d+)(?:\/|$)/u.exec(url.pathname);
6969
return claim(host, match);
7070
}
71-
// Azure DevOps, both the current host and the per-organisation one it replaced. `_git` is part
72-
// of the repository path there, as it is in the remote URL the identity is read from.
73-
if (isHostOf(host, "dev.azure.com") || host.endsWith(".visualstudio.com")) {
74-
const match = /^\/((?:[^/]+\/)*_git\/[^/]+)\/pullrequest\/(\d+)(?:\/|$)/u.exec(url.pathname);
75-
return claim(host, match);
76-
}
77-
return null;
71+
// Azure DevOps, Azure DevOps Server included, whose collection path comes before the project.
72+
// `_git` is part of the repository path there, as it is in the remote URL the identity is read
73+
// from.
74+
const azure = /^\/((?:[^/]+\/)*_git\/[^/]+)\/pullrequest\/(\d+)(?:\/|$)/u.exec(url.pathname);
75+
return azure ? claim(host, azure) : null;
7876
}
7977

8078
function claim(host: string, match: RegExpExecArray | null): ChangeRequestLink | null {

0 commit comments

Comments
 (0)