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): show full pull request references (#98782)

Paul D'Ambra7081cb6d703e
diff --git a/products/desktop/packages/ui/src/features/editor/components/GithubRefChip.stories.tsx b/products/desktop/packages/ui/src/features/editor/components/GithubRefChip.stories.tsx
index 2883b99a5ec4..d5377ae24aea 100644
--- a/products/desktop/packages/ui/src/features/editor/components/GithubRefChip.stories.tsx
+++ b/products/desktop/packages/ui/src/features/editor/components/GithubRefChip.stories.tsx
@@ -1,4 +1,8 @@
-import { GithubRefChip } from "@posthog/ui/features/editor/components/GithubRefChip";
+import { GitPullRequestIcon } from "@phosphor-icons/react";
+import {
+ GithubRefChip,
+ GithubRefChipLink,
+} from "@posthog/ui/features/editor/components/GithubRefChip";
import {
PrRefChip,
type PrRefDetails,
@@ -27,9 +31,42 @@ export const WithoutLiveDetails: Story = {
),
};
+const NINE_DIGIT_PULL_REQUEST = "example-org/example-repo#123456789";
+
+export const PullRequestNumberWidth: Story = {
+ render: () => (
+ <div className="flex flex-col items-start gap-4 text-[13px]">
+ <div className="flex flex-col gap-1">
+ <span className="text-(--gray-11)">Before</span>
+ <div className="w-[22ch]">
+ <GithubRefChipLink
+ href="https://github.com/example-org/example-repo/pull/123456789"
+ icon={GitPullRequestIcon}
+ preservePrNumber={false}
+ >
+ {NINE_DIGIT_PULL_REQUEST}
+ </GithubRefChipLink>
+ </div>
+ </div>
+ <div className="flex flex-col gap-1">
+ <span className="text-(--gray-11)">After</span>
+ <div className="w-[22ch]">
+ <GithubRefChipLink
+ href="https://github.com/example-org/example-repo/pull/123456789"
+ icon={GitPullRequestIcon}
+ preservePrNumber
+ >
+ {NINE_DIGIT_PULL_REQUEST}
+ </GithubRefChipLink>
+ </div>
+ </div>
+ </div>
+ ),
+};
+
const LIFECYCLE_CASES: { number: number; details: PrRefDetails }[] = [
{
- number: 101,
+ number: 123456789,
details: {
state: "open",
merged: false,
diff --git a/products/desktop/packages/ui/src/features/editor/components/GithubRefChip.test.tsx b/products/desktop/packages/ui/src/features/editor/components/GithubRefChip.test.tsx
index 0175de3073e1..fa1961a18d3b 100644
--- a/products/desktop/packages/ui/src/features/editor/components/GithubRefChip.test.tsx
+++ b/products/desktop/packages/ui/src/features/editor/components/GithubRefChip.test.tsx
@@ -16,6 +16,37 @@ describe("GithubRefChip", () => {
expect(carrier?.getAttribute(GITHUB_REF_URL_ATTR)).toBe(href);
});
+ it("truncates a pull request label from the start so its number survives", () => {
+ render(
+ <GithubRefChip
+ href="https://github.com/PostHog/posthog/pull/123456789"
+ kind="pr"
+ >
+ PostHog/posthog#123456789
+ </GithubRefChip>,
+ );
+
+ const label = screen.getByText("PostHog/posthog#123456789");
+ expect(label).toHaveAttribute("dir", "ltr");
+ expect(label.parentElement).toHaveAttribute("dir", "rtl");
+ expect(label.parentElement).toHaveClass("truncate");
+ });
+
+ it("leaves a label that puts its number first alone", () => {
+ render(
+ <GithubRefChip
+ href="https://github.com/PostHog/posthog/pull/42"
+ kind="pr"
+ >
+ #42 - Fix the sign-up redirect
+ </GithubRefChip>,
+ );
+
+ expect(
+ screen.getByText("#42 - Fix the sign-up redirect"),
+ ).not.toHaveAttribute("dir");
+ });
+
it("lets a nested right-click target resolve the URL via closest()", () => {
const href = "https://github.com/PostHog/posthog/issues/42";
render(
diff --git a/products/desktop/packages/ui/src/features/editor/components/GithubRefChip.tsx b/products/desktop/packages/ui/src/features/editor/components/GithubRefChip.tsx
index 3d15ad83c251..a40758478c2d 100644
--- a/products/desktop/packages/ui/src/features/editor/components/GithubRefChip.tsx
+++ b/products/desktop/packages/ui/src/features/editor/components/GithubRefChip.tsx
@@ -18,9 +18,20 @@ interface GithubRefChipLinkProps
/** Names the icon for screen readers. Omit when the icon says nothing extra. */
iconLabel?: string;
toneClass?: string;
+ /** Keeps a trailing `#number` visible when the label truncates. */
+ preservePrNumber?: boolean;
children: ReactNode;
}
+/**
+ * Truncation removes the end of a label, which for `owner/repo#number` is the
+ * number that tells two pull requests apart. Only labels that end in a number
+ * qualify: `#12 - Title` already keeps its number at the front.
+ */
+function endsWithRefNumber(label: ReactNode): boolean {
+ return typeof label === "string" && /#\d+$/.test(label);
+}
+
/**
* The chip every GitHub reference renders as: a quill button whose element is
* the link itself, so the chip is one thing to click and one thing to tab to.
@@ -32,9 +43,22 @@ export const GithubRefChipLink = forwardRef<
HTMLButtonElement,
GithubRefChipLinkProps
>(function GithubRefChipLink(
- { href, icon: RefIcon, iconLabel, toneClass, children, ...buttonProps },
+ {
+ href,
+ icon: RefIcon,
+ iconLabel,
+ toneClass,
+ preservePrNumber,
+ children,
+ ...buttonProps
+ },
ref,
) {
+ // A right-to-left box puts the ellipsis at the start, so the trailing number
+ // survives truncation. The inner isolate keeps the text itself left-to-right.
+ // The label stays one text node on purpose: a number in its own flex item
+ // puts a line break into copied text.
+ const ellipsisAtStart = preservePrNumber && endsWithRefNumber(children);
return (
<Button
ref={ref}
@@ -73,8 +97,9 @@ export const GithubRefChipLink = forwardRef<
"inline-block max-w-[min(16rem,calc(100%-1rem))] truncate align-top",
toneClass,
)}
+ dir={ellipsisAtStart ? "rtl" : undefined}
>
- {children}
+ {ellipsisAtStart ? <span dir="ltr">{children}</span> : children}
</span>
</Button>
);
@@ -98,6 +123,7 @@ export function GithubRefChip({
<GithubRefChipLink
href={href}
icon={kind === "pr" ? GitPullRequestIcon : GithubLogoIcon}
+ preservePrNumber={kind === "pr"}
>
{children}
</GithubRefChipLink>
diff --git a/products/desktop/packages/ui/src/features/editor/components/PrRefChip.test.tsx b/products/desktop/packages/ui/src/features/editor/components/PrRefChip.test.tsx
index 76e0ce6f5025..08119297e2e9 100644
--- a/products/desktop/packages/ui/src/features/editor/components/PrRefChip.test.tsx
+++ b/products/desktop/packages/ui/src/features/editor/components/PrRefChip.test.tsx
@@ -37,6 +37,9 @@ describe("PrRefChip", () => {
expect(
await screen.findByText("Show pull request status in sessions"),
).toBeInTheDocument();
+ expect(
+ document.querySelector('[data-slot="tooltip-content"]'),
+ ).toHaveTextContent("PostHog/posthog#23985");
expect(screen.getByText("Created by @octocat")).toBeInTheDocument();
expect(screen.getByText("CI passed")).toBeInTheDocument();
});
diff --git a/products/desktop/packages/ui/src/features/editor/components/PrRefChip.tsx b/products/desktop/packages/ui/src/features/editor/components/PrRefChip.tsx
index 17a464a9df1c..b8fa6ed7cb96 100644
--- a/products/desktop/packages/ui/src/features/editor/components/PrRefChip.tsx
+++ b/products/desktop/packages/ui/src/features/editor/components/PrRefChip.tsx
@@ -75,6 +75,7 @@ export function PrRefChip({
icon={StatusIcon}
iconLabel={iconLabel}
toneClass={toneClass}
+ preservePrNumber
>
{children}
</GithubRefChipLink>
@@ -84,6 +85,7 @@ export function PrRefChip({
{/* The tooltip surface is inverted, so its contents inherit that color
rather than the page foreground/muted tokens. */}
<div className="flex min-w-0 flex-col gap-1.5 text-start">
+ <span className="font-mono text-current/70">{children}</span>
<div className="flex items-center gap-1.5 font-medium">
<StatusIcon
size={12}