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): mobile label pull request comment links (#87720)

Tom Owers75ed0b3c27e2
diff --git a/products/desktop/apps/mobile/src/features/chat/components/MarkdownText.test.tsx b/products/desktop/apps/mobile/src/features/chat/components/MarkdownText.test.tsx
index ba50e97d3bc1..901cdc3a7f02 100644
--- a/products/desktop/apps/mobile/src/features/chat/components/MarkdownText.test.tsx
+++ b/products/desktop/apps/mobile/src/features/chat/components/MarkdownText.test.tsx
@@ -11,6 +11,21 @@ vi.mock("@/features/auth", () => ({
getCloudUrlFromRegion: () => null,
}));
+vi.mock("@/lib/theme", () => ({
+ useThemeColors: () => ({
+ gray: { 11: "#444444", 12: "#000000" },
+ status: { success: "#00aa00", error: "#cc0000" },
+ }),
+ toRgba: (hex: string, alpha: number) => `${hex}/${alpha}`,
+ MERGED_COLOR: "#8e4ec6",
+}));
+
+vi.mock("@/lib/openExternalUrl", () => ({ openExternalUrl: vi.fn() }));
+
+vi.mock("../../tasks/hooks/usePrStatus", () => ({
+ usePrStatus: () => ({ data: undefined }),
+}));
+
function renderTree(content: string): string {
let renderer: ReturnType<typeof create> | null = null;
act(() => {
@@ -58,6 +73,20 @@ describe("MarkdownText", () => {
present: ["Loading"],
absent: ["<flag"],
},
+ {
+ name: "bare review-comment link labels the comment",
+ content:
+ "[https://github.com/o/r/pull/12#discussion_r99](https://github.com/o/r/pull/12#discussion_r99)",
+ present: ["Comment on PR #12"],
+ absent: ["o/r#12"],
+ },
+ {
+ name: "review-comment link with explicit text keeps that text",
+ content:
+ "[see the review](https://github.com/o/r/pull/12#discussion_r99)",
+ present: ["see the review"],
+ absent: ["Comment on PR"],
+ },
])("$name", ({ content, present, absent }) => {
const tree = renderTree(content);
for (const marker of present) {
diff --git a/products/desktop/apps/mobile/src/features/chat/components/MarkdownText.tsx b/products/desktop/apps/mobile/src/features/chat/components/MarkdownText.tsx
index 17da74ac9555..7b8f262ce2e7 100644
--- a/products/desktop/apps/mobile/src/features/chat/components/MarkdownText.tsx
+++ b/products/desktop/apps/mobile/src/features/chat/components/MarkdownText.tsx
@@ -367,9 +367,10 @@ function renderInline(
const githubRef = parseGithubIssueUrl(url);
if (githubRef) {
const isAutoLink = linkText === url;
- const label = isAutoLink
- ? `${githubRef.owner}/${githubRef.repo}#${githubRef.number}`
- : linkText;
+ const autoLinkLabel = githubRef.isReviewComment
+ ? `Comment on PR #${githubRef.number}`
+ : `${githubRef.owner}/${githubRef.repo}#${githubRef.number}`;
+ const label = isAutoLink ? autoLinkLabel : linkText;
nodes.push(
<GithubRefChip
key={match.index}
diff --git a/products/desktop/apps/mobile/src/lib/githubIssueUrl.test.ts b/products/desktop/apps/mobile/src/lib/githubIssueUrl.test.ts
new file mode 100644
index 000000000000..311427d85c63
--- /dev/null
+++ b/products/desktop/apps/mobile/src/lib/githubIssueUrl.test.ts
@@ -0,0 +1,47 @@
+import { describe, expect, it } from "vitest";
+import { parseGithubIssueUrl } from "./githubIssueUrl";
+
+describe("parseGithubIssueUrl", () => {
+ it.each([
+ {
+ name: "PR review comment via discussion anchor",
+ url: "https://github.com/o/r/pull/12#discussion_r3647131256",
+ isReviewComment: true,
+ },
+ {
+ name: "PR review comment via files anchor",
+ url: "https://github.com/o/r/pull/12/files#r3647131256",
+ isReviewComment: true,
+ },
+ {
+ name: "PR issue comment is not a review comment",
+ url: "https://github.com/o/r/pull/12#issuecomment-123",
+ isReviewComment: false,
+ },
+ {
+ name: "issue with an r-style anchor is not a review comment",
+ url: "https://github.com/o/r/issues/12#r3647131256",
+ isReviewComment: false,
+ },
+ {
+ name: "plain PR url",
+ url: "https://github.com/o/r/pull/12",
+ isReviewComment: false,
+ },
+ {
+ name: "plain issue url",
+ url: "https://github.com/o/r/issues/12",
+ isReviewComment: false,
+ },
+ ])("$name", ({ url, isReviewComment }) => {
+ expect(parseGithubIssueUrl(url)?.isReviewComment).toBe(isReviewComment);
+ });
+
+ it("keeps the comment anchor in the normalized url", () => {
+ expect(
+ parseGithubIssueUrl(
+ "https://github.com/o/r/pull/12#discussion_r3647131256",
+ )?.normalizedUrl,
+ ).toBe("https://github.com/o/r/pull/12#discussion_r3647131256");
+ });
+});
diff --git a/products/desktop/apps/mobile/src/lib/githubIssueUrl.ts b/products/desktop/apps/mobile/src/lib/githubIssueUrl.ts
index f7101d4fde45..56b17e8ae5f0 100644
--- a/products/desktop/apps/mobile/src/lib/githubIssueUrl.ts
+++ b/products/desktop/apps/mobile/src/lib/githubIssueUrl.ts
@@ -6,6 +6,7 @@ export interface ParsedGithubIssueUrl {
repo: string;
number: number;
normalizedUrl: string;
+ isReviewComment: boolean;
}
const GITHUB_ISSUE_URL_PATTERN =
@@ -26,11 +27,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),
};
}