Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions packages/junior-github/src/reply-markdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion packages/junior-github/src/tools/create-issue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -263,7 +264,7 @@ async function createGitHubIssueRequest(
title: nonEmptyString(input.title, "title"),
body: appendGitHubFooter(
appendGitHubRequesterAttribution(
input.body ?? "",
linkifyGitHubReferences(input.body ?? ""),
ctx,
await resolveGitHubRequester(ctx),
),
Expand Down
7 changes: 6 additions & 1 deletion packages/junior-github/src/tools/create-pull-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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
Expand All @@ -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),
}),
Expand Down
3 changes: 2 additions & 1 deletion packages/junior-github/src/tools/update-issue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -141,7 +142,7 @@ export function createGitHubUpdateIssueTool(ctx: {
? {
body: appendGitHubFooter(
appendGitHubRequesterAttribution(
update.body,
linkifyGitHubReferences(update.body),
ctx,
await resolveGitHubRequester(ctx),
),
Expand Down
7 changes: 6 additions & 1 deletion packages/junior-github/src/tools/update-pull-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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,
),
Expand Down
4 changes: 2 additions & 2 deletions packages/junior-github/tests/github-plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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" },
Expand Down Expand Up @@ -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<!-- junior-request-attribution:start -->\nvia **David Cramer**.\n<!-- junior-request-attribution:end -->",
body: "PR body for [getsentry/sentry-docs#20303](https://github.com/getsentry/sentry-docs/issues/20303)\n\n<!-- junior-request-attribution:start -->\nvia **David Cramer**.\n<!-- junior-request-attribution:end -->",
draft: true,
});
});
Expand Down
Loading