diff --git a/packages/junior-github/src/reply-markdown.ts b/packages/junior-github/src/reply-markdown.ts index 684ba4d09c..6ce028d2e4 100644 --- a/packages/junior-github/src/reply-markdown.ts +++ b/packages/junior-github/src/reply-markdown.ts @@ -94,7 +94,10 @@ function linkifyLine(line: string): string { continue; } - if (line.startsWith("https://", index) || line.startsWith("http://", index)) { + if ( + line.startsWith("https://", index) || + line.startsWith("http://", index) + ) { const match = /^https?:\/\/\S+/.exec(line.slice(index)); if (match) { output += match[0]; @@ -120,7 +123,13 @@ function linkifyLine(line: string): string { return output; } -/** Linkify GitHub issue and pull request shorthand outside Markdown code. */ +/** + * Linkify GitHub issue and pull request shorthand outside Markdown code. + * + * GitHub bodies need this too: a repository autolink prefix such as `SENTRY-` + * can claim part of bare `getsentry/sentry-docs#1` and link the rest as a + * same-repository reference. GitHub does not rewrite Markdown link labels. + */ export function linkifyGitHubReferences(text: string): string { let openFenceLength = 0; return text diff --git a/packages/junior-github/src/tools/create-issue.ts b/packages/junior-github/src/tools/create-issue.ts index 1c3e567e28..f533ff053f 100644 --- a/packages/junior-github/src/tools/create-issue.ts +++ b/packages/junior-github/src/tools/create-issue.ts @@ -17,6 +17,7 @@ import { Type, type Static } from "@sinclair/typebox"; import { Value } from "@sinclair/typebox/value"; import { z } from "zod"; import { appendGitHubFooter } from "./footer.js"; +import { linkifyGitHubReferences } from "../reply-markdown.js"; import { gitHubIssueSubscribable } from "../events/issue.js"; import { appendGitHubRequesterAttribution, @@ -263,7 +264,7 @@ async function createGitHubIssueRequest( title: nonEmptyString(input.title, "title"), body: appendGitHubFooter( appendGitHubRequesterAttribution( - input.body ?? "", + linkifyGitHubReferences(input.body ?? ""), ctx, await resolveGitHubRequester(ctx), ), diff --git a/packages/junior-github/src/tools/create-pull-request.ts b/packages/junior-github/src/tools/create-pull-request.ts index c82144c182..4911aa292a 100644 --- a/packages/junior-github/src/tools/create-pull-request.ts +++ b/packages/junior-github/src/tools/create-pull-request.ts @@ -19,6 +19,7 @@ import { Type, type Static } from "@sinclair/typebox"; import { Value } from "@sinclair/typebox/value"; import { z } from "zod"; import { appendGitHubFooter } from "./footer.js"; +import { linkifyGitHubReferences } from "../reply-markdown.js"; import { gitHubPullRequestCreateWatch, gitHubPullRequestSubscribable, @@ -284,7 +285,11 @@ function createGitHubPullRequestRequest( head: nonEmptyString(input.head, "head"), base: nonEmptyString(input.base, "base"), body: appendGitHubFooter( - appendGitHubRequesterAttribution(input.body ?? "", ctx, requester), + appendGitHubRequesterAttribution( + linkifyGitHubReferences(input.body ?? ""), + ctx, + requester, + ), conversationId, dashboardUrl, ), diff --git a/packages/junior-github/src/tools/submit-pull-request-review.ts b/packages/junior-github/src/tools/submit-pull-request-review.ts index 4bb5e57b98..3e03a8b00a 100644 --- a/packages/junior-github/src/tools/submit-pull-request-review.ts +++ b/packages/junior-github/src/tools/submit-pull-request-review.ts @@ -5,6 +5,7 @@ import { PluginToolInputError, pluginToolOutputSchema, } from "@sentry/junior-plugin-api"; +import { linkifyGitHubReferences } from "../reply-markdown.js"; import { z } from "zod"; const reviewCommentSchema = z .object({ @@ -119,7 +120,7 @@ export function createGitHubSubmitPullRequestReviewTool(egress: PluginEgress) { const repo = parseRepo(review.repo); const comments = review.comments?.map((comment) => ({ path: comment.path, - body: comment.body, + body: linkifyGitHubReferences(comment.body), line: comment.line, side: comment.side, ...(comment.startLine !== undefined @@ -142,7 +143,7 @@ export function createGitHubSubmitPullRequestReviewTool(egress: PluginEgress) { "X-GitHub-Api-Version": "2022-11-28", }, body: JSON.stringify({ - body: review.body, + body: linkifyGitHubReferences(review.body), event: review.event, ...(comments ? { comments } : undefined), }), diff --git a/packages/junior-github/src/tools/update-issue.ts b/packages/junior-github/src/tools/update-issue.ts index 483ba35dfd..fe6c589f40 100644 --- a/packages/junior-github/src/tools/update-issue.ts +++ b/packages/junior-github/src/tools/update-issue.ts @@ -21,6 +21,7 @@ import { resolveGitHubRequester, } from "../tool-support/attribution.js"; import { appendGitHubFooter } from "./footer.js"; +import { linkifyGitHubReferences } from "../reply-markdown.js"; const inputSchema = z .object({ @@ -141,7 +142,7 @@ export function createGitHubUpdateIssueTool(ctx: { ? { body: appendGitHubFooter( appendGitHubRequesterAttribution( - update.body, + linkifyGitHubReferences(update.body), ctx, await resolveGitHubRequester(ctx), ), diff --git a/packages/junior-github/src/tools/update-pull-request.ts b/packages/junior-github/src/tools/update-pull-request.ts index c6f6041231..c640fc89cc 100644 --- a/packages/junior-github/src/tools/update-pull-request.ts +++ b/packages/junior-github/src/tools/update-pull-request.ts @@ -23,6 +23,7 @@ import { import type { GitHubDb } from "../db/database.js"; import { recordGitHubPullRequestRequester } from "../pull-request-requesters/store.js"; import { appendGitHubFooter } from "./footer.js"; +import { linkifyGitHubReferences } from "../reply-markdown.js"; const inputSchema = z .object({ @@ -226,7 +227,11 @@ export function createGitHubUpdatePullRequestTool(ctx: { ...(update.body !== undefined ? { body: appendGitHubFooter( - appendGitHubRequesterAttribution(update.body, ctx, requester), + appendGitHubRequesterAttribution( + linkifyGitHubReferences(update.body), + ctx, + requester, + ), nonEmptyString(ctx.conversationId, "conversationId"), ctx.slack?.conversationLink?.url, ), diff --git a/packages/junior-github/tests/github-plugin.test.ts b/packages/junior-github/tests/github-plugin.test.ts index dec14d08c4..182b3e23a5 100644 --- a/packages/junior-github/tests/github-plugin.test.ts +++ b/packages/junior-github/tests/github-plugin.test.ts @@ -1475,7 +1475,7 @@ Conversation: \`local:test:old-conversation\` title: "Typed PR", head: "dcramer/gh-660-pr-create", base: "main", - body: "PR body", + body: "PR body for getsentry/sentry-docs#20303", draft: true, }, { toolCallId: "call-create-pull-request" }, @@ -1550,7 +1550,7 @@ Conversation: \`local:test:old-conversation\` title: "Typed PR", head: "dcramer/gh-660-pr-create", base: "main", - body: "PR body\n\n\nvia **David Cramer**.\n", + body: "PR body for [getsentry/sentry-docs#20303](https://github.com/getsentry/sentry-docs/issues/20303)\n\n\nvia **David Cramer**.\n", draft: true, }); });