Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(desktop): label pull request comment links (#87545)

Adam Bowker477457fc61bf
diff --git a/products/desktop/packages/core/src/message-editor/githubIssueUrl.test.ts b/products/desktop/packages/core/src/message-editor/githubIssueUrl.test.ts
index c62db88f34d0..1421246f61fc 100644
--- a/products/desktop/packages/core/src/message-editor/githubIssueUrl.test.ts
+++ b/products/desktop/packages/core/src/message-editor/githubIssueUrl.test.ts
@@ -19,6 +19,7 @@ describe("parseGithubIssueUrl", () => {
repo: "code",
number: 1808,
normalizedUrl: "https://github.com/PostHog/code/issues/1808",
+ isReviewComment: false,
},
},
{
@@ -30,6 +31,7 @@ describe("parseGithubIssueUrl", () => {
repo: "code",
number: 1454,
normalizedUrl: "https://github.com/PostHog/code/pull/1454",
+ isReviewComment: false,
},
},
{
@@ -41,6 +43,7 @@ describe("parseGithubIssueUrl", () => {
repo: "code",
number: 1454,
normalizedUrl: "https://github.com/PostHog/code/pull/1454",
+ isReviewComment: false,
},
},
{
@@ -52,6 +55,7 @@ describe("parseGithubIssueUrl", () => {
repo: "code",
number: 1808,
normalizedUrl: "https://github.com/PostHog/code/issues/1808",
+ isReviewComment: false,
},
},
{
@@ -64,6 +68,7 @@ describe("parseGithubIssueUrl", () => {
number: 1808,
normalizedUrl:
"https://github.com/PostHog/code/issues/1808#issuecomment-123",
+ isReviewComment: false,
},
},
{
@@ -77,6 +82,7 @@ describe("parseGithubIssueUrl", () => {
number: 72409,
normalizedUrl:
"https://github.com/PostHog/posthog/pull/72409#discussion_r3647131256",
+ isReviewComment: true,
},
},
{
@@ -89,6 +95,7 @@ describe("parseGithubIssueUrl", () => {
number: 1454,
normalizedUrl:
"https://github.com/PostHog/code/pull/1454/files#r3647131256",
+ isReviewComment: true,
},
},
{
@@ -100,6 +107,7 @@ describe("parseGithubIssueUrl", () => {
repo: "code",
number: 1808,
normalizedUrl: "https://github.com/PostHog/code/issues/1808",
+ isReviewComment: false,
},
},
{
@@ -111,6 +119,7 @@ describe("parseGithubIssueUrl", () => {
repo: "code",
number: 1808,
normalizedUrl: "https://github.com/PostHog/code/issues/1808",
+ isReviewComment: false,
},
},
{
@@ -122,6 +131,7 @@ describe("parseGithubIssueUrl", () => {
repo: "code",
number: 1,
normalizedUrl: "https://github.com/PostHog/code/issues/1",
+ isReviewComment: false,
},
},
];
diff --git a/products/desktop/packages/core/src/message-editor/githubIssueUrl.ts b/products/desktop/packages/core/src/message-editor/githubIssueUrl.ts
index a90569205058..5a63330b3098 100644
--- a/products/desktop/packages/core/src/message-editor/githubIssueUrl.ts
+++ b/products/desktop/packages/core/src/message-editor/githubIssueUrl.ts
@@ -8,6 +8,7 @@ export interface ParsedGithubIssueUrl {
repo: string;
number: number;
normalizedUrl: string;
+ isReviewComment: boolean;
}
const GITHUB_ISSUE_URL_PATTERN =
@@ -28,11 +29,13 @@ export function parseGithubIssueUrl(text: string): ParsedGithubIssueUrl | null {
// they were copied from. Without a fragment the tab/query suffix is noise.
const hashIndex = suffix.indexOf("#");
const hasFragment = hashIndex !== -1 && hashIndex < suffix.length - 1;
+ const fragment = hasFragment ? suffix.slice(hashIndex + 1) : "";
return {
kind,
owner,
repo,
number,
normalizedUrl: `https://github.com/${owner}/${repo}/${segment}/${number}${hasFragment ? suffix : ""}`,
+ isReviewComment: kind === "pr" && /^(?:discussion_)?r\d+$/.test(fragment),
};
}
diff --git a/products/desktop/packages/ui/src/features/editor/components/githubRefChipFor.tsx b/products/desktop/packages/ui/src/features/editor/components/githubRefChipFor.tsx
index d0cf81c9b828..10355e586f6f 100644
--- a/products/desktop/packages/ui/src/features/editor/components/githubRefChipFor.tsx
+++ b/products/desktop/packages/ui/src/features/editor/components/githubRefChipFor.tsx
@@ -17,9 +17,12 @@ export function githubRefChipFor(
// A bare URL reads as noise in a sentence, so it becomes owner/repo#number.
const isAutoLink = typeof children === "string" && children === href;
- const label = isAutoLink
- ? `${githubRef.owner}/${githubRef.repo}#${githubRef.number}`
- : children;
+ const label =
+ isAutoLink && githubRef.isReviewComment
+ ? `Comment on PR #${githubRef.number}`
+ : isAutoLink
+ ? `${githubRef.owner}/${githubRef.repo}#${githubRef.number}`
+ : children;
if (githubRef.kind === "pr") {
return (
diff --git a/products/desktop/packages/ui/src/features/sessions/components/chat-thread/ChatMarkdown.test.tsx b/products/desktop/packages/ui/src/features/sessions/components/chat-thread/ChatMarkdown.test.tsx
index 1d5b022b2223..2f5d7a546c0e 100644
--- a/products/desktop/packages/ui/src/features/sessions/components/chat-thread/ChatMarkdown.test.tsx
+++ b/products/desktop/packages/ui/src/features/sessions/components/chat-thread/ChatMarkdown.test.tsx
@@ -73,6 +73,15 @@ Verdict: valid.
'data-github-ref-url="https://github.com/PostHog/posthog/pull/23985"',
);
});
+
+ it("labels a pull request review comment without dropping its anchor", () => {
+ const href =
+ "https://github.com/PostHog/posthog/pull/86811/changes#r3832262653";
+ const html = renderToStaticMarkup(<ChatMarkdown content={href} />);
+
+ expect(html).toContain("Comment on PR #86811");
+ expect(html).toContain(`data-github-ref-url="${href}"`);
+ });
});
describe("ChatMarkdown object tags", () => {