Skip to content

Commit 1c8e79e

Browse files
fix(mcp): accept GitCafe pull request URLs in link/unlink/watch tools (#23899)
Co-authored-by: Claude Fable 5.1 <[email protected]>
1 parent 23bd753 commit 1c8e79e

4 files changed

Lines changed: 38 additions & 2 deletions

File tree

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,24 @@ describe("pull request toolkit handlers", () => {
265265
}),
266266
);
267267

268+
it.effect("links a GitCafe pull request by its canonical /pull/ URL", () =>
269+
Effect.gen(function* () {
270+
const harness = yield* makeHarness();
271+
const result = yield* harness.call("link_pull_request", {
272+
url: "https://git.cafe/pingdotgg/t3code/pull/23897",
273+
});
274+
expect(result).toMatchObject({
275+
host: "git.cafe",
276+
repository: "pingdotgg/t3code",
277+
number: 23897,
278+
alreadyLinked: false,
279+
});
280+
expect(yield* Ref.get(harness.commands)).toMatchObject([
281+
{ type: "thread.pull-request.link", host: "git.cafe", number: 23897 },
282+
]);
283+
}),
284+
);
285+
268286
it.effect("watching an unlinked pull request links it first", () =>
269287
Effect.gen(function* () {
270288
const harness = yield* makeHarness();

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,20 @@ describe("parseChangeRequestUrl", () => {
1919
});
2020
});
2121

22+
it("reads a GitCafe pull request at its canonical /pull/ path and the older /pulls/ path", () => {
23+
for (const path of ["pull", "pulls"]) {
24+
expect(
25+
parseChangeRequestUrl(`https://git.cafe/PingDotGG/T3Code/${path}/23897`),
26+
path,
27+
).toEqual({ host: "git.cafe", repository: "pingdotgg/t3code", number: 23897 });
28+
}
29+
expect(parseChangeRequestUrl("https://staging.git.cafe/team/repo/pull/7/files")).toEqual({
30+
host: "staging.git.cafe",
31+
repository: "team/repo",
32+
number: 7,
33+
});
34+
});
35+
2236
it("reads Forgejo URLs even when the hostname contains github", () => {
2337
expect(parseChangeRequestUrl("https://github.internal/team/repo/pulls/7")).toEqual({
2438
host: "github.internal",
@@ -106,6 +120,9 @@ describe("parseChangeRequestUrl", () => {
106120
it("claims nothing it cannot be sure of", () => {
107121
for (const link of [
108122
"https://github.com/t3tools/t3code/issues/123",
123+
"https://git.cafe/pingdotgg/t3code/issues/23897",
124+
"https://git.cafe/pingdotgg/t3code/pull/abc",
125+
"https://git.cafe/pingdotgg/t3code",
109126
"https://github.com/t3tools/t3code/commit/0a1b2c3",
110127
"https://github.com/t3tools/t3code",
111128
"https://github.com/t3tools/t3code/pull/abc",

‎packages/shared/src/changeRequestUrl.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ export function parseChangeRequestUrl(targetUrl: string): ChangeRequestLink | nu
2929
const host = url.hostname.toLowerCase();
3030

3131
if (host === "git.cafe" || host === "staging.git.cafe") {
32-
const match = /^\/([^/]+\/[^/]+)\/pulls\/(\d+)(?:\/|$)/u.exec(url.pathname);
32+
// GitCafe serves pull requests at `/pull/<n>` and redirects the older `/pulls/<n>` there.
33+
const match = /^\/([^/]+\/[^/]+)\/pulls?\/(\d+)(?:\/|$)/u.exec(url.pathname);
3334
if (match) return claim(host, match);
3435
} else {
3536
if (isHostOf(host, "github.com", "github")) {

‎packages/source-control-gitcafe/src/client/definition.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export const definition = defineSourceControlClient({
7171
try {
7272
return (
7373
GITCAFE_HOSTS.has(new URL(url).hostname.toLowerCase()) &&
74-
isChangeRequestPath(url, "/pulls/")
74+
(isChangeRequestPath(url, "/pull/") || isChangeRequestPath(url, "/pulls/"))
7575
);
7676
} catch {
7777
return false;

0 commit comments

Comments
 (0)