Skip to content

Commit a53e187

Browse files
fix: preserve Azure Server pull request link origins
1 parent 9ae266e commit a53e187

2 files changed

Lines changed: 31 additions & 18 deletions

File tree

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,13 @@ const resolveTarget = Effect.fn("PullRequestsToolkit.resolveTarget")(function* (
9999
project?.repositoryIdentity?.locator.remoteUrl,
100100
) ??
101101
(/(?:^|\/)_git\/[^/]+$/u.test(repository)
102-
? changeRequestUrlFor("azure-devops", host, repository, input.number)
102+
? changeRequestUrlFor(
103+
"azure-devops",
104+
host,
105+
repository,
106+
input.number,
107+
project?.repositoryIdentity?.locator.remoteUrl,
108+
)
103109
: null) ??
104110
`https://${host}/${repository}/pull/${input.number}`;
105111
return {

‎packages/shared/src/changeRequestUrl.ts‎

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,22 @@ function claim(host: string, match: RegExpExecArray | null): ChangeRequestLink |
6161
: null;
6262
}
6363

64+
function remoteWebOrigin(host: string, remoteUrl: string | undefined): string {
65+
try {
66+
const remote = new URL(remoteUrl ?? "");
67+
if (
68+
(remote.protocol === "http:" || remote.protocol === "https:") &&
69+
(remote.hostname.toLowerCase() === host.toLowerCase() ||
70+
remote.host.toLowerCase() === host.toLowerCase())
71+
) {
72+
return remote.origin;
73+
}
74+
} catch {
75+
// SSH remotes do not specify the server's web origin.
76+
}
77+
return `https://${host}`;
78+
}
79+
6480
export function changeRequestUrlFor(
6581
kind: string | null | undefined,
6682
host: string,
@@ -73,27 +89,18 @@ export function changeRequestUrlFor(
7389
return `https://${host}/${repository}/pull/${number}`;
7490
case "gitcafe":
7591
return `https://${host}/${repository}/pulls/${number}`;
76-
case "forgejo": {
77-
try {
78-
const remote = new URL(remoteUrl ?? "");
79-
if (
80-
(remote.protocol === "http:" || remote.protocol === "https:") &&
81-
(remote.hostname.toLowerCase() === host.toLowerCase() ||
82-
remote.host.toLowerCase() === host.toLowerCase())
83-
) {
84-
return `${remote.origin}/${repository}/pulls/${number}`;
85-
}
86-
} catch {
87-
// SSH remotes do not specify the server's web origin.
88-
}
89-
return `https://${host}/${repository}/pulls/${number}`;
90-
}
92+
case "forgejo":
93+
return `${remoteWebOrigin(host, remoteUrl)}/${repository}/pulls/${number}`;
9194
case "gitlab":
9295
return `https://${host}/${repository}/-/merge_requests/${number}`;
9396
case "bitbucket":
9497
return `https://${host}/${repository}/pull-requests/${number}`;
95-
case "azure-devops":
96-
return `https://${canonicalRepositoryKey(`${host}/${repository}`.toLowerCase())}/pullrequest/${number}`;
98+
case "azure-devops": {
99+
const [canonicalHost = host, ...path] = canonicalRepositoryKey(
100+
`${host}/${repository}`.toLowerCase(),
101+
).split("/");
102+
return `${remoteWebOrigin(canonicalHost, remoteUrl)}/${path.join("/")}/pullrequest/${number}`;
103+
}
97104
default:
98105
return null;
99106
}

0 commit comments

Comments
 (0)