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.

feat(desktop): mobile live pull request status in chat (#86293)

Tom Owersb32d24144fa7
diff --git a/products/desktop/apps/mobile/src/features/chat/components/GithubRefChip.test.tsx b/products/desktop/apps/mobile/src/features/chat/components/GithubRefChip.test.tsx
new file mode 100644
index 000000000000..6a53234c909a
--- /dev/null
+++ b/products/desktop/apps/mobile/src/features/chat/components/GithubRefChip.test.tsx
@@ -0,0 +1,114 @@
+import { createElement } from "react";
+import { act, create } from "react-test-renderer";
+import { describe, expect, it, vi } from "vitest";
+import type { PrStatus } from "../../tasks/hooks/usePrStatus";
+import { GithubRefChip } from "./GithubRefChip";
+
+vi.mock("@/lib/theme", () => ({
+ useThemeColors: () => ({
+ gray: { 11: "#444444" },
+ 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: vi.fn() }));
+
+import { usePrStatus } from "../../tasks/hooks/usePrStatus";
+
+const mockUsePrStatus = vi.mocked(usePrStatus);
+
+function setStatus(data: PrStatus | null | undefined) {
+ mockUsePrStatus.mockReturnValue({ data } as ReturnType<typeof usePrStatus>);
+}
+
+const href = "https://github.com/a/b/pull/1";
+
+function render(props: Parameters<typeof GithubRefChip>[0]) {
+ let renderer: ReturnType<typeof create> | null = null;
+ act(() => {
+ renderer = create(createElement(GithubRefChip, props));
+ });
+ if (!renderer) throw new Error("Renderer not created");
+ return renderer as ReturnType<typeof create>;
+}
+
+function chip(renderer: ReturnType<typeof create>): {
+ accessibilityLabel: string;
+ color: string | undefined;
+} {
+ const node = renderer.root.findAll(
+ (n) => typeof n.props?.onPress === "function",
+ )[0];
+ return {
+ accessibilityLabel: node.props.accessibilityLabel as string,
+ color: (node.props.style as { color?: string } | undefined)?.color,
+ };
+}
+
+const base: PrStatus = {
+ state: "open",
+ merged: false,
+ draft: false,
+ additions: 0,
+ deletions: 0,
+};
+
+describe("GithubRefChip", () => {
+ it.each([
+ { name: "open", status: { ...base }, color: "#00aa00", state: "open" },
+ {
+ name: "draft",
+ status: { ...base, draft: true },
+ color: "#444444",
+ state: "draft",
+ },
+ {
+ name: "closed",
+ status: { ...base, state: "closed" as const },
+ color: "#cc0000",
+ state: "closed",
+ },
+ {
+ name: "merged",
+ status: { ...base, state: "closed" as const, merged: true },
+ color: "#8e4ec6",
+ state: "merged",
+ },
+ ])("tints a $name PR and names its state", ({ status, color, state }) => {
+ setStatus(status);
+ const { accessibilityLabel, color: rendered } = chip(
+ render({ href, kind: "pr", label: "a/b#1" }),
+ );
+ expect(rendered).toBe(color);
+ expect(accessibilityLabel).toBe(`GitHub pull request a/b#1, ${state}`);
+ });
+
+ it.each([
+ { name: "loading", data: undefined },
+ { name: "unresolved (private/404/non-GitHub)", data: null },
+ ])("falls back to a neutral, untinted PR chip when $name", ({ data }) => {
+ setStatus(data);
+ const { accessibilityLabel, color } = chip(
+ render({ href, kind: "pr", label: "a/b#1" }),
+ );
+ expect(color).toBeUndefined();
+ expect(accessibilityLabel).toBe("GitHub pull request a/b#1");
+ });
+
+ it("renders an issue as a neutral chip without fetching status", () => {
+ const { accessibilityLabel, color } = chip(
+ render({
+ href: "https://github.com/a/b/issues/1",
+ kind: "issue",
+ label: "a/b#1",
+ }),
+ );
+ expect(color).toBeUndefined();
+ expect(accessibilityLabel).toBe("GitHub issue a/b#1");
+ expect(mockUsePrStatus).not.toHaveBeenCalled();
+ });
+});
diff --git a/products/desktop/apps/mobile/src/features/chat/components/GithubRefChip.tsx b/products/desktop/apps/mobile/src/features/chat/components/GithubRefChip.tsx
index a65f35ad5adb..91953cf6e5c7 100644
--- a/products/desktop/apps/mobile/src/features/chat/components/GithubRefChip.tsx
+++ b/products/desktop/apps/mobile/src/features/chat/components/GithubRefChip.tsx
@@ -1,5 +1,16 @@
+import {
+ getPrVisualConfig,
+ type PrVisualConfig,
+} from "@posthog/core/git-interaction/prStatus";
import { Text } from "react-native";
+import { usePrStatus } from "@/features/tasks/hooks/usePrStatus";
import { openExternalUrl } from "@/lib/openExternalUrl";
+import {
+ MERGED_COLOR,
+ type ThemeColors,
+ toRgba,
+ useThemeColors,
+} from "@/lib/theme";
interface GithubRefChipProps {
href: string;
@@ -7,17 +18,80 @@ interface GithubRefChipProps {
label: string;
}
+function toneColor(color: PrVisualConfig["color"], theme: ThemeColors): string {
+ switch (color) {
+ case "green":
+ return theme.status.success;
+ case "red":
+ return theme.status.error;
+ case "purple":
+ return MERGED_COLOR;
+ default:
+ return theme.gray[11];
+ }
+}
+
// Rendered as a plain <Text> so it can be embedded inline within markdown
// paragraphs (RN does not allow <View> children inside <Text>). The icon
// from the desktop chip is omitted for the same reason — visual distinction
// comes from the chip background + monospace + accent color.
export function GithubRefChip({ href, kind, label }: GithubRefChipProps) {
+ if (kind === "pr") {
+ return <GithubPrRefChip href={href} label={label} />;
+ }
+ return (
+ <RefChip
+ href={href}
+ label={label}
+ accessibilityLabel={`GitHub issue ${label}`}
+ />
+ );
+}
+
+// The PR's live lifecycle drives the chip's tint and its accessibility label,
+// since a phone has no hover card to carry the state. Unknown status (still
+// loading, private repo, or a failed request) falls back to the neutral chip.
+function GithubPrRefChip({ href, label }: { href: string; label: string }) {
+ const { data: status } = usePrStatus(href);
+ const themeColors = useThemeColors();
+
+ const config = status
+ ? getPrVisualConfig(status.state, status.merged, status.draft)
+ : undefined;
+ return (
+ <RefChip
+ href={href}
+ label={label}
+ accessibilityLabel={
+ config
+ ? `GitHub pull request ${label}, ${config.label.toLowerCase()}`
+ : `GitHub pull request ${label}`
+ }
+ color={config ? toneColor(config.color, themeColors) : undefined}
+ />
+ );
+}
+
+function RefChip({
+ href,
+ label,
+ accessibilityLabel,
+ color,
+}: {
+ href: string;
+ label: string;
+ accessibilityLabel: string;
+ color?: string;
+}) {
return (
<Text
onPress={() => openExternalUrl(href)}
className="rounded-md bg-gray-3 px-1.5 py-0.5 font-mono text-[11px] text-accent-11"
+ style={
+ color ? { backgroundColor: toRgba(color, 0.12), color } : undefined
+ }
accessibilityRole="link"
- accessibilityLabel={`GitHub ${kind === "pr" ? "pull request" : "issue"} ${label}`}
+ accessibilityLabel={accessibilityLabel}
>
{label}
</Text>
diff --git a/products/desktop/apps/mobile/src/features/tasks/components/PrStatusBadge.test.tsx b/products/desktop/apps/mobile/src/features/tasks/components/PrStatusBadge.test.tsx
index a330030fde20..c71e512fc852 100644
--- a/products/desktop/apps/mobile/src/features/tasks/components/PrStatusBadge.test.tsx
+++ b/products/desktop/apps/mobile/src/features/tasks/components/PrStatusBadge.test.tsx
@@ -17,6 +17,7 @@ vi.mock("@/lib/theme", () => ({
status: { success: "#00aa00", error: "#cc0000" },
}),
toRgba: (hex: string, alpha: number) => `${hex}/${alpha}`,
+ MERGED_COLOR: "#8e4ec6",
}));
vi.mock("@/lib/openExternalUrl", () => ({ openExternalUrl: vi.fn() }));
diff --git a/products/desktop/apps/mobile/src/features/tasks/components/PrStatusBadge.tsx b/products/desktop/apps/mobile/src/features/tasks/components/PrStatusBadge.tsx
index 646b4918663c..04c39034dc87 100644
--- a/products/desktop/apps/mobile/src/features/tasks/components/PrStatusBadge.tsx
+++ b/products/desktop/apps/mobile/src/features/tasks/components/PrStatusBadge.tsx
@@ -1,7 +1,7 @@
import { GitMerge, GitPullRequest } from "phosphor-react-native";
import { Pressable } from "react-native";
import { openExternalUrl } from "@/lib/openExternalUrl";
-import { toRgba, useThemeColors } from "@/lib/theme";
+import { MERGED_COLOR, toRgba, useThemeColors } from "@/lib/theme";
import { usePrStatus } from "../hooks/usePrStatus";
interface PrStatusBadgeProps {
@@ -13,11 +13,6 @@ interface PrStatusBadgeProps {
size?: "sm" | "md";
}
-// Mirrors the desktop "merged" PR color (Radix purple-9 family). Theme tokens
-// don't include a purple, and merged-PR purple is recognisable enough that a
-// fixed value works in both light and dark.
-const MERGED_COLOR = "#8e4ec6";
-
export function PrStatusBadge({
prUrl,
hideWhenUnresolved = false,
diff --git a/products/desktop/apps/mobile/src/lib/theme.ts b/products/desktop/apps/mobile/src/lib/theme.ts
index 0fa4d0e819cc..9dd229b9b215 100644
--- a/products/desktop/apps/mobile/src/lib/theme.ts
+++ b/products/desktop/apps/mobile/src/lib/theme.ts
@@ -172,3 +172,8 @@ export function useThemeColors(): ThemeColors {
export function toRgba(hex: string, alpha: number): string {
return hexToRgba(hex, alpha);
}
+
+// Merged-PR purple, mirrored from the desktop app. The theme has no purple
+// scale, and this purple is recognisable enough that a fixed value works in
+// both light and dark.
+export const MERGED_COLOR = "#8e4ec6";