Skip to content
TypeScript

fix(mcp): accept GitCafe pull request URLs in link/unlink/watch tools (#23899)

Julius Marminge1c8e79ec18a7
diff --git a/apps/server/src/mcp/toolkits/pullRequests/handlers.test.ts b/apps/server/src/mcp/toolkits/pullRequests/handlers.test.ts
index e9ee5a05ad9..c49715eb7eb 100644
--- a/apps/server/src/mcp/toolkits/pullRequests/handlers.test.ts
+++ b/apps/server/src/mcp/toolkits/pullRequests/handlers.test.ts
@@ -265,6 +265,24 @@ describe("pull request toolkit handlers", () => {
}),
);
+ it.effect("links a GitCafe pull request by its canonical /pull/ URL", () =>
+ Effect.gen(function* () {
+ const harness = yield* makeHarness();
+ const result = yield* harness.call("link_pull_request", {
+ url: "https://git.cafe/pingdotgg/t3code/pull/23897",
+ });
+ expect(result).toMatchObject({
+ host: "git.cafe",
+ repository: "pingdotgg/t3code",
+ number: 23897,
+ alreadyLinked: false,
+ });
+ expect(yield* Ref.get(harness.commands)).toMatchObject([
+ { type: "thread.pull-request.link", host: "git.cafe", number: 23897 },
+ ]);
+ }),
+ );
+
it.effect("watching an unlinked pull request links it first", () =>
Effect.gen(function* () {
const harness = yield* makeHarness();
diff --git a/packages/shared/src/changeRequestUrl.test.ts b/packages/shared/src/changeRequestUrl.test.ts
index e1ac1e77ac6..0c7a469753e 100644
--- a/packages/shared/src/changeRequestUrl.test.ts
+++ b/packages/shared/src/changeRequestUrl.test.ts
@@ -19,6 +19,20 @@ describe("parseChangeRequestUrl", () => {
});
});
+ it("reads a GitCafe pull request at its canonical /pull/ path and the older /pulls/ path", () => {
+ for (const path of ["pull", "pulls"]) {
+ expect(
+ parseChangeRequestUrl(`https://git.cafe/PingDotGG/T3Code/${path}/23897`),
+ path,
+ ).toEqual({ host: "git.cafe", repository: "pingdotgg/t3code", number: 23897 });
+ }
+ expect(parseChangeRequestUrl("https://staging.git.cafe/team/repo/pull/7/files")).toEqual({
+ host: "staging.git.cafe",
+ repository: "team/repo",
+ number: 7,
+ });
+ });
+
it("reads Forgejo URLs even when the hostname contains github", () => {
expect(parseChangeRequestUrl("https://github.internal/team/repo/pulls/7")).toEqual({
host: "github.internal",
@@ -106,6 +120,9 @@ describe("parseChangeRequestUrl", () => {
it("claims nothing it cannot be sure of", () => {
for (const link of [
"https://github.com/t3tools/t3code/issues/123",
+ "https://git.cafe/pingdotgg/t3code/issues/23897",
+ "https://git.cafe/pingdotgg/t3code/pull/abc",
+ "https://git.cafe/pingdotgg/t3code",
"https://github.com/t3tools/t3code/commit/0a1b2c3",
"https://github.com/t3tools/t3code",
"https://github.com/t3tools/t3code/pull/abc",
diff --git a/packages/shared/src/changeRequestUrl.ts b/packages/shared/src/changeRequestUrl.ts
index a39593a9c09..129e4d090ee 100644
--- a/packages/shared/src/changeRequestUrl.ts
+++ b/packages/shared/src/changeRequestUrl.ts
@@ -29,7 +29,8 @@ export function parseChangeRequestUrl(targetUrl: string): ChangeRequestLink | nu
const host = url.hostname.toLowerCase();
if (host === "git.cafe" || host === "staging.git.cafe") {
- const match = /^\/([^/]+\/[^/]+)\/pulls\/(\d+)(?:\/|$)/u.exec(url.pathname);
+ // GitCafe serves pull requests at `/pull/<n>` and redirects the older `/pulls/<n>` there.
+ const match = /^\/([^/]+\/[^/]+)\/pulls?\/(\d+)(?:\/|$)/u.exec(url.pathname);
if (match) return claim(host, match);
} else {
if (isHostOf(host, "github.com", "github")) {
diff --git a/packages/source-control-gitcafe/src/client/definition.ts b/packages/source-control-gitcafe/src/client/definition.ts
index 2204cac261c..c33cb45d517 100644
--- a/packages/source-control-gitcafe/src/client/definition.ts
+++ b/packages/source-control-gitcafe/src/client/definition.ts
@@ -71,7 +71,7 @@ export const definition = defineSourceControlClient({
try {
return (
GITCAFE_HOSTS.has(new URL(url).hostname.toLowerCase()) &&
- isChangeRequestPath(url, "/pulls/")
+ (isChangeRequestPath(url, "/pull/") || isChangeRequestPath(url, "/pulls/"))
);
} catch {
return false;