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
21 changes: 21 additions & 0 deletions packages/core/src/message-editor/content.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
xmlToContent,
xmlToPlainText,
} from "./content";
import { buildGithubRefPlaceholderChip } from "./githubIssueChip";

describe("xmlToContent", () => {
it("parses a file tag into a file chip", () => {
Expand Down Expand Up @@ -97,6 +98,26 @@ describe("xmlToContent", () => {
);
});

it("serializes an unresolved github_pr placeholder chip with an empty title", () => {
const content: EditorContent = {
segments: [
{
type: "chip",
chip: buildGithubRefPlaceholderChip({
kind: "pr",
owner: "org",
repo: "repo",
number: 71827,
normalizedUrl: "https://github.com/org/repo/pull/71827",
}),
},
],
};
expect(contentToXml(content)).toBe(
'<github_pr number="71827" title="" url="https://github.com/org/repo/pull/71827" />',
);
});

it("round-trips a github_pr chip", () => {
const content: EditorContent = {
segments: [
Expand Down
7 changes: 6 additions & 1 deletion packages/core/src/message-editor/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ export interface MentionChip {
skillName?: string;
}

/** Chip title shown while a pasted GitHub ref's real title is being fetched. */
export const GITHUB_REF_PLACEHOLDER_TITLE = "Loading...";

export interface FileAttachment {
id: string;
label: string;
Expand Down Expand Up @@ -83,7 +86,9 @@ export function contentToXml(content: EditorContent): string {
case "github_pr": {
const labelMatch = chip.label.match(/^#(\d+)(?:\s*-\s*(.*))?$/);
const number = labelMatch?.[1] ?? "";
const title = labelMatch?.[2] ?? "";
const rawTitle = labelMatch?.[2] ?? "";
// A chip sent before its title fetch resolves must not leak the placeholder
const title = rawTitle === GITHUB_REF_PLACEHOLDER_TITLE ? "" : rawTitle;
Comment thread
luke-belton marked this conversation as resolved.
return `<${chip.type} number="${escapeXmlAttr(number)}" title="${escapeXmlAttr(title)}" url="${escapedId}" />`;
}
default:
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/message-editor/githubIssueChip.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { GithubRefState } from "@posthog/shared";
import type { MentionChip } from "./content";
import { GITHUB_REF_PLACEHOLDER_TITLE, type MentionChip } from "./content";
import type { ParsedGithubIssueUrl } from "./githubIssueUrl";

export interface GithubIssueChipSource {
Expand Down Expand Up @@ -43,7 +43,7 @@ export function buildGithubRefPlaceholderChip(
): MentionChip {
const source = {
number: parsed.number,
title: "Loading...",
title: GITHUB_REF_PLACEHOLDER_TITLE,
url: parsed.normalizedUrl,
};
return parsed.kind === "pr"
Expand Down
Loading