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
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
type PullRequestSummary,
resolveEnvironmentMachineKind,
type ScopedThreadRef,
pullRequestConversationThreads,
} from "@t3tools/contracts";
import {
ArrowDownUpIcon,
Expand Down Expand Up @@ -1278,14 +1279,14 @@ export function PullRequestDetailPanel({

/**
* Brings a remark into the composer beside this panel, with the pull request it belongs to,
* and nothing else: what to ask about it is the reader's to write. A remark on a line travels
* as its whole conversation, the way fixing one does.
* and nothing else: what to ask about it is the reader's to write. A remark in a thread travels
* as its whole conversation, so a reply arrives with what it answers.
*/
const addCommentToChat = (subject: PullRequestChatSubject) => {
if (!detail || attachTarget === null) return;
const thread =
subject.kind === "comment"
? detail.reviewThreads.find((candidate) =>
? pullRequestConversationThreads(detail).find((candidate) =>
candidate.comments.some((comment) => comment.id === subject.comment.id),
)
: undefined;
Expand Down
10 changes: 4 additions & 6 deletions apps/web/src/components/pullRequest/PullRequestSummaryTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -248,15 +248,14 @@ function CommentBody({
}

/**
* What Add to chat hands over for a remark: a remark on a line goes as its whole conversation,
* the way fixing one does. Null when there are no words in it to talk about.
* What Add to chat hands over for a remark: a remark in a thread goes as its whole conversation.
* Null when there are no words in it to talk about.
*/
function chatSubject(
comment: PullRequestComment,
thread: PullRequestConversationThread | undefined,
): PullRequestChatSubject | null {
// An overview thread has no line to attach, so it goes as its opening remark, as fixing it does.
if (thread !== undefined && thread.path !== null) {
if (thread !== undefined) {
return thread.comments.some((entry) => visibleBody(entry.body) !== null)
? { kind: "thread", thread }
: null;
Expand Down Expand Up @@ -768,8 +767,7 @@ export function PullRequestSummaryTab({
? null
: { kind: "comment", comment }
: { kind: "thread", thread };
// A reply goes with its conversation, from the card that heads it.
const chat = reply ? null : chatSubject(comment, thread);
const chat = chatSubject(comment, thread);
return (
<article
key={`${detail.url}:${comment.id}`}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,6 @@ function ConversationCard({
onOpen,
reactions,
showPath = true,
reply = false,
resolveButton = null,
}: {
event: PullRequestTimelineEvent;
Expand All @@ -250,8 +249,6 @@ function ConversationCard({
onOpen: (url: string) => void;
reactions: ReactionSurface;
showPath?: boolean;
/** A reply goes with its conversation, from the card that heads it. */
reply?: boolean;
resolveButton?: ReactNode;
}) {
const gt = useGT();
Expand Down Expand Up @@ -335,7 +332,7 @@ function ConversationCard({
/>
) : null}
{resolveButton}
{event.body && event.comment && !reply ? (
{event.body && event.comment ? (
<AddToChatButton comment={event.comment} reactions={reactions} />
) : null}
{canReact || event.reactions.length > 0 ? (
Expand Down Expand Up @@ -600,7 +597,6 @@ function ReviewThreadEvent({
onOpen={onOpen}
reactions={reactions}
showPath={false}
reply
/>
))}
</div>
Expand Down
119 changes: 119 additions & 0 deletions apps/web/src/components/pullRequest/pullRequestDetail.logic.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { SourceControlProviderKind } from "@t3tools/contracts";
import {
COMPOSER_CONTEXT_REVIEW_TEXT_MAX_CHARS,
GitCommandError,
ProjectId,
type PullRequestCheck,
Expand Down Expand Up @@ -1241,6 +1242,124 @@ describe("adding a remark to the chat", () => {
expect(sent).toContain("more characters of the review summary are omitted");
});

it("brings an overview thread's replies along with its opening remark", () => {
const context = buildPullRequestCommentContext(pullRequest, {
kind: "thread",
thread: {
id: "t1",
path: null,
line: null,
side: "right",
isResolved: false,
isOutdated: false,
comments: [
remark("c1", "Does this skip the prompt?"),
{
...remark("c2", "One concern remains."),
author: { login: "coderabbit", name: null, avatarUrl: null },
},
],
},
});

expect(context && reviewCommentContextLabel(context)).toBe("#42 @octocat thread");
expect(context?.text).toBe(
"octocat: Does this skip the prompt?\ncoderabbit: One concern remains.",
);
});

it("keeps a reply when the remark it answers runs past the length bound", () => {
const context = buildPullRequestCommentContext(pullRequest, {
kind: "thread",
thread: {
id: "t1",
path: "src/app.ts",
line: 3,
side: "right",
isResolved: false,
isOutdated: false,
comments: [remark("c1", "x".repeat(5_000)), remark("c2", "One concern remains.")],
},
});

expect(context?.text).toMatch(/\.\.\.\noctocat: One concern remains\.$/u);
});

it("puts a remark's visible text ahead of its collapsed details", () => {
const context = buildPullRequestCommentContext(pullRequest, {
kind: "comment",
comment: remark(
"c1",
`<details title="open logs">\n<summary>Analysis chain</summary>\n\n${"script ".repeat(400)}\n</details>\n\nOne concern remains.`,
),
});

expect(context?.text).toMatch(/^octocat: One concern remains\.\n\n<details title/u);
});

it("closes a details section whose closing tag has text after it", () => {
const context = buildPullRequestCommentContext(pullRequest, {
kind: "comment",
comment: remark("c1", `<details>\n${"script ".repeat(400)}</details> Tail.\nVisible.`),
});
const nested = buildPullRequestCommentContext(pullRequest, {
kind: "comment",
comment: remark(
"c2",
`<details><details>\n<details>\n${"script ".repeat(400)}</details></details>\n${"more ".repeat(400)}\n</details>\nFinding.`,
),
});

expect(context?.text).toMatch(/^octocat: Tail\.\nVisible\./u);
expect(nested?.text).toMatch(/^octocat: Finding\./u);
});

it("gives way to the newest replies when a thread outgrows what the composer sends", () => {
const comments = Array.from({ length: 20 }, (_, index) =>
remark(`c${index}`, `${index} ${"x".repeat(990)}`),
);
const context = buildPullRequestCommentContext(pullRequest, {
kind: "thread",
thread: {
id: "t1",
path: null,
line: null,
side: "right",
isResolved: false,
isOutdated: false,
comments,
nextCommentsCursor: "more",
},
});

expect(context?.text.length).toBeLessThanOrEqual(COMPOSER_CONTEXT_REVIEW_TEXT_MAX_CHARS);
expect(context?.text).toMatch(/^octocat: 0 /u);
expect(context?.text).toMatch(/\n\(5 earlier replies omitted\.\)\noctocat: 6 /u);
expect(context?.text).toMatch(/octocat: 19 x+\.\.\.\n\(More replies are on the host/u);
});

it("keeps a details section that starts open in place", () => {
const context = buildPullRequestCommentContext(pullRequest, {
kind: "comment",
comment: remark(
"c1",
`<details open>\n<summary>Finding</summary>\n\nRename x.\n</details>\n\n${"Context. ".repeat(200)}`,
),
});

expect(context?.text).toMatch(/^octocat: <details open>/u);
});

it("leaves a details tag shown inside code where it is", () => {
const body = `\`\`\`html\n<details>\n<summary>Example</summary>\n</details>\n\`\`\`\n${"Explanation. ".repeat(100)}`;
const context = buildPullRequestCommentContext(pullRequest, {
kind: "comment",
comment: remark("c1", body),
});

expect(context?.text).toMatch(/^octocat: ```html\n<details>/u);
});

it("keeps every added remark when a later hand-off lands", () => {
const added = ["c1", "c2"].flatMap(
(id) =>
Expand Down
Loading
Loading