Open History to see the last commit
1import {
2 capitalizeTerm,
3 sourceControlClients,
4} from "@t3tools/client-runtime/source-control-clients";
5import { useAtomCommand } from "~/state/use-atom-command";
6import type {
7 EnvironmentId,
8 PullRequestComment,
9 PullRequestDetailView,
10 PullRequestRef,
11 PullRequestReviewThread,
12 ScopedThreadRef,
13} from "@t3tools/contracts";
14import {
15 ArrowDownUpIcon,
16 ChevronDownIcon,
17 ChevronRightIcon,
18 HammerIcon,
19 ListFilterIcon,
20 TagIcon,
21 UsersIcon,
22} from "lucide-react";
23import * as Schema from "effect/Schema";
24import { useRef, useState, type ReactNode } from "react";
25
26import { pullRequestEnvironment } from "~/state/pullRequests";
27import { useLocalStorage } from "~/hooks/useLocalStorage";
28import { cn } from "~/lib/utils";
29import { useOpenLink } from "~/browser/useOpenLink";
30import { RelativeTime } from "~/components/RelativeTime";
31
32import { Button } from "../ui/button";
33import { PullRequestEditButton } from "./PullRequestEditButton";
34import { Collapsible, CollapsiblePanel, CollapsibleTrigger } from "../ui/collapsible";
35import {
36 Menu,
37 MenuCheckboxItem,
38 MenuGroup,
39 MenuGroupLabel,
40 MenuPopup,
41 MenuTrigger,
42} from "../ui/menu";
43import { toastManager } from "../ui/toast";
44import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";
45import {
46 PullRequestActorLabel,
47 PullRequestCheckStatusIcon,
48 pullRequestCheckStatusLabel,
49 PullRequestLabelChip,
50 PullRequestReviewOutcomeBadge,
51 pullRequestReviewOutcomeLabel,
52 pullRequestReviewOutcomeRingClassName,
53 pullRequestReviewOutcomeStaleLabel,
54} from "./pullRequestPresentation";
55import { PullRequestLabelPicker } from "./PullRequestLabelPicker";
56import { PullRequestReviewerPicker } from "./PullRequestReviewerPicker";
57import { PullRequestActivityUnavailableState } from "./PullRequestActivityUnavailableState";
58import {
59 filterPullRequestConversationItems,
60 isPullRequestCommentFinished,
61 latestPullRequestReviewOutcomes,
62 orderPullRequestComments,
63 pagePullRequestConversationItems,
64 pullRequestConversationItemComments,
65 pullRequestConversationItems,
66 pullRequestFindingKey,
67 pullRequestReviewOutcome,
68 visibleBody,
69 type PullRequestConversationItem,
70 type PullRequestFinding,
71} from "./pullRequestDetail.logic";
72import {
73 canEditPullRequestChangeRequest,
74 canEditPullRequestComment,
75} from "@t3tools/client-runtime/pull-request-editing";
76import { PullRequestMarkdown } from "./PullRequestMarkdown";
77import { PullRequestCommentBody } from "./PullRequestCommentBody";
78import { PullRequestMoreReplies } from "./PullRequestMoreReplies";
79import { PullRequestMarkdownEditor } from "./PullRequestMarkdownEditor";
80import { PullRequestReactionBar } from "./PullRequestReactions";
81import { PullRequestConversationGhost } from "./PullRequestGhosts";
82import { sectionCollapseAnchorScrollTop } from "./pullRequestSummaryScroll.logic";
83
84function reviewerKey(login: string): string {
85 return login.toLowerCase();
86}
87
88function CommentIdentity({
89 comment,
90 detail,
91}: {
92 comment: PullRequestComment;
93 detail: PullRequestDetailView;
94}) {
95 const actor = comment.author;
96 const profileUrl = actor
97 ? sourceControlClients.get(detail.provider).authorProfileUrl(actor.login, detail.url)
98 : null;
99 return (
100 <div className="flex min-w-0 flex-1 flex-wrap items-baseline gap-x-2 gap-y-1 text-xs">
101 <PullRequestActorLabel actor={actor} profileUrl={profileUrl} className="max-w-full" />
102 <Tooltip>
103 <TooltipTrigger
104 render={
105 comment.url ? (
106 <a
107 href={comment.url}
108 target="_blank"
109 rel="noopener noreferrer"
110 className="text-muted-foreground hover:text-foreground hover:underline"
111 />
112 ) : (
113 <span className="text-muted-foreground" />
114 )
115 }
116 >
117 <time dateTime={comment.createdAt}>
118 <RelativeTime timestamp={comment.createdAt} />
119 </time>
120 </TooltipTrigger>
121 <TooltipPopup>
122 {new Date(comment.createdAt).toLocaleString()}
123 {comment.url ? " · Open comment on host" : ""}
124 </TooltipPopup>
125 </Tooltip>
126 </div>
127 );
128}
129
130function CommentLocation({
131 comment,
132 thread,
133}: {
134 comment: PullRequestComment;
135 thread: PullRequestReviewThread | undefined;
136}) {
137 const path = thread?.path ?? comment.path;
138 if (!path) return null;
139 const label = `${path}${thread?.line ? `:${thread.line}` : ""}`;
140 return (
141 <div className="mt-2 flex min-w-0 items-center gap-2 text-xs text-muted-foreground">
142 <Tooltip>
143 <TooltipTrigger render={<span className="truncate font-mono" />}>{label}</TooltipTrigger>
144 <TooltipPopup>{label}</TooltipPopup>
145 </Tooltip>
146 {thread?.isOutdated ? <span className="shrink-0">Outdated</span> : null}
147 </div>
148 );
149}
150
151function reviewStateLabel(state: string): string {
152 const words = state.toLowerCase().replace(/_/g, " ");
153 return words.charAt(0).toUpperCase() + words.slice(1);
154}
155
156interface CommentEditing {
157 readonly cwd: string;
158 readonly environmentId: EnvironmentId;
159 readonly threadRef: ScopedThreadRef | null;
160 readonly canEdit: (comment: PullRequestComment) => boolean;
161 readonly editingId: string | null;
162 readonly saving: boolean;
163 readonly onEdit: (comment: PullRequestComment | null) => void;
164 readonly onSave: (comment: PullRequestComment, body: string) => void;
165}
166
167function CommentBody({
168 comment,
169 editing,
170 className,
171}: {
172 comment: PullRequestComment;
173 editing: CommentEditing;
174 className?: string | undefined;
175}) {
176 if (editing.editingId === comment.id) {
177 return (
178 <PullRequestMarkdownEditor
179 className={className}
180 value={comment.body}
181 cwd={editing.cwd}
182 environmentId={editing.environmentId}
183 threadRef={editing.threadRef}
184 label="Edit comment"
185 saving={editing.saving}
186 onSave={(body) => editing.onSave(comment, body)}
187 onCancel={() => editing.onEdit(null)}
188 />
189 );
190 }
191 return (
192 <div className={cn("flex items-start gap-1", className)}>
193 <PullRequestCommentBody
194 key={comment.id}
195 className="min-w-0 flex-1"
196 text={comment.body}
197 cwd={editing.cwd}
198 environmentId={editing.environmentId}
199 threadRef={editing.threadRef}
200 />
201 {editing.canEdit(comment) ? (
202 <PullRequestEditButton aria-label="Edit comment" onClick={() => editing.onEdit(comment)} />
203 ) : null}
204 </div>
205 );
206}
207
208function CollapsedComment({
209 comment,
210 editing,
211 label,
212 body,
213 reactionBar,
214 detail,
215 thread,
216 replyCount = 0,
217 replies = null,
218 moreReplies = null,
219}: {
220 comment: PullRequestComment;
221 editing: CommentEditing;
222 label: string;
223 body: string | null;
224 reactionBar: ReactNode;
225 detail: PullRequestDetailView;
226 thread: PullRequestReviewThread | undefined;
227 replyCount?: number;
228 replies?: ReactNode;
229 moreReplies?: ReactNode;
230}) {
231 const [open, setOpen] = useState(false);
232 const statusTriggerRef = useRef<HTMLButtonElement>(null);
233 return (
234 <Collapsible open={open} onOpenChange={setOpen}>
235 <article className="group rounded-lg border border-border/60 [contain-intrinsic-block-size:44px] [content-visibility:auto]">
236 <div className="p-3">
237 <div className="flex flex-wrap items-baseline gap-2">
238 <CommentIdentity comment={comment} detail={detail} />
239 {replyCount > 0 ? (
240 <span className="shrink-0 py-1 text-xs text-muted-foreground">
241 {replyCount} {replyCount === 1 ? "reply" : "replies"}
242 </span>
243 ) : null}
244 <CollapsibleTrigger
245 ref={statusTriggerRef}
246 className="flex shrink-0 items-center gap-1.5 rounded-md px-2 py-1 text-xs text-muted-foreground hover:bg-muted hover:text-foreground"
247 >
248 {label}
249 <ChevronDownIcon
250 aria-hidden
251 className={cn("size-3.5 transition-transform", open && "rotate-180")}
252 />
253 </CollapsibleTrigger>
254 {reactionBar}
255 </div>
256 <CommentLocation comment={comment} thread={thread} />
257 {!open && body ? (
258 <CollapsibleTrigger
259 className="mt-2 block w-full truncate text-left text-xs text-muted-foreground hover:text-foreground"
260 onClick={() => statusTriggerRef.current?.focus({ preventScroll: true })}
261 >
262 {body
263 .replace(/<!--[\s\S]*?-->/gu, "")
264 .replace(/^\s*>?\s*\[!\w+\]\s*$/gmu, "")
265 .replace(/!?(\[([^\]]+)\])\([^)]*\)/gu, "$2")
266 .replace(/^[\s>#*-]+/gmu, "")
267 .replace(/[*`]/gu, "")
268 .replace(/\s+/g, " ")
269 .trim()}
270 </CollapsibleTrigger>
271 ) : null}
272 </div>
273 <CollapsiblePanel>
274 {open ? (
275 <div className="px-3 pb-3">
276 {body === null && !editing.canEdit(comment) ? null : (
277 <CommentBody className="mt-2" comment={comment} editing={editing} />
278 )}
279 {replies ? <div className="mt-3">{replies}</div> : null}
280 </div>
281 ) : null}
282 </CollapsiblePanel>
283 {moreReplies ? <div className="px-3 pb-3">{moreReplies}</div> : null}
284 </article>
285 </Collapsible>
286 );
287}
288
289function MetaRow({
290 icon,
291 label,
292 children,
293}: {
294 icon: ReactNode;
295 label: string;
296 children: ReactNode;
297}) {
298 return (
299 <div className="grid min-h-7 min-w-0 grid-cols-[6rem_minmax(0,1fr)] items-center gap-2 text-xs sm:min-h-6">
300 <span className="flex items-center gap-1.5 text-muted-foreground">
301 {icon}
302 {label}
303 </span>
304 <span className="min-w-0 text-foreground">{children}</span>
305 </div>
306 );
307}
308
309function Section({
310 title,
311 defaultOpen = true,
312 keepMounted = false,
313 actions,
314 children,
315}: {
316 title: string;
317 defaultOpen?: boolean;
318 keepMounted?: boolean;
319 actions?: ReactNode;
320 children: ReactNode;
321}) {
322 const [open, setOpen] = useState(defaultOpen);
323 const headingRef = useRef<HTMLDivElement>(null);
324 const setOpenWithScrollAnchor = (nextOpen: boolean) => {
325 if (!nextOpen) {
326 const heading = headingRef.current;
327 const section = heading?.closest<HTMLElement>("[data-pull-request-summary-section]");
328 const scroller = heading?.closest<HTMLElement>("[data-pull-request-summary-scroll]");
329 if (heading && section && scroller) {
330 const target = sectionCollapseAnchorScrollTop({
331 scrollTop: scroller.scrollTop,
332 viewportTop: scroller.getBoundingClientRect().top,
333 sectionTop: section.getBoundingClientRect().top,
334 headingTop: heading.getBoundingClientRect().top,
335 });
336 // Adjust before paint to keep the collapsed heading in place.
337 if (target !== null) scroller.scrollTop = target;
338 }
339 }
340 setOpen(nextOpen);
341 };
342 return (
343 <Collapsible
344 open={open}
345 onOpenChange={setOpenWithScrollAnchor}
346 render={<section aria-label={title} />}
347 data-pull-request-summary-section
348 >
349 <div
350 ref={headingRef}
351 className="sticky top-0 z-10 flex w-full items-center bg-background pr-4"
352 >
353 <CollapsibleTrigger className="flex min-w-0 flex-1 items-center gap-1.5 px-4 py-3 text-left text-xs font-medium text-muted-foreground hover:text-foreground">
354 <span>{title}</span>
355 <ChevronRightIcon
356 aria-hidden
357 className={cn(
358 "size-3.5 text-muted-foreground/60 transition-transform",
359 open && "rotate-90",
360 )}
361 />
362 </CollapsibleTrigger>
363 {actions}
364 </div>
365 <CollapsiblePanel keepMounted={keepMounted}>
366 <div className="px-4 pb-4">{children}</div>
367 </CollapsiblePanel>
368 </Collapsible>
369 );
370}
371
372const COMMENT_PAGE = 10;
373
374const COMMENT_FILTER_STORAGE_KEY = "t3code:pull-request-comment-filter:v1";
375const CommentFilterSchema = Schema.Struct({ bots: Schema.Boolean, resolved: Schema.Boolean });
376const DEFAULT_COMMENT_FILTER: typeof CommentFilterSchema.Type = { bots: false, resolved: false };
377
378export function PullRequestSummaryTab({
379 scrollerRef,
380 environmentId,
381 threadRef,
382 reference,
383 detail,
384 activityPending,
385 checksStale = false,
386 activityError,
387 pendingFinding,
388 fixFindingLabel = "Fix in a thread",
389 fixCheckLabel = "Fix",
390 onFixFinding,
391 onRefresh,
392 onRefreshChecks = onRefresh,
393}: {
394 scrollerRef: (node: HTMLDivElement | null) => void;
395 environmentId: EnvironmentId;
396 threadRef: ScopedThreadRef | null;
397 reference: PullRequestRef;
398 detail: PullRequestDetailView;
399 activityPending: boolean;
400 checksStale?: boolean;
401 activityError: string | null;
402 pendingFinding?: string | null;
403 fixFindingLabel?: string;
404 fixCheckLabel?: string;
405 onFixFinding?: (finding: PullRequestFinding) => void;
406 onRefresh: () => void;
407 onRefreshChecks?: () => void;
408}) {
409 const terminology = sourceControlClients.get(detail.provider).changeRequest;
410 const [shown, setShown] = useState({ url: detail.url, count: COMMENT_PAGE });
411 const shownConversations = shown.url === detail.url ? shown.count : COMMENT_PAGE;
412 const [commentFilter, setCommentFilter] = useLocalStorage(
413 COMMENT_FILTER_STORAGE_KEY,
414 DEFAULT_COMMENT_FILTER,
415 CommentFilterSchema,
416 );
417 const items = pullRequestConversationItems(detail.comments, detail.reviewThreads);
418 const filteredItems = filterPullRequestConversationItems(items, commentFilter);
419 const commentCount = items.reduce(
420 (count, item) => count + pullRequestConversationItemComments(item).length,
421 0,
422 );
423 const filteredOutCount =
424 commentCount -
425 filteredItems.reduce(
426 (count, item) => count + pullRequestConversationItemComments(item).length,
427 0,
428 );
429 const { shown: recentItems, hidden: hiddenConversationCount } = pagePullRequestConversationItems(
430 filteredItems,
431 shownConversations,
432 );
433 const [commentOrder, setCommentOrder] = useState<"newest" | "oldest">("newest");
434 const visibleItems = orderPullRequestComments(recentItems, commentOrder);
435 const showOldestCommentsButton =
436 hiddenConversationCount > 0 ? (
437 <Button
438 size="sm"
439 variant="outline"
440 className="w-full"
441 onClick={() => setShown({ url: detail.url, count: shownConversations + COMMENT_PAGE })}
442 >
443 Show {Math.min(hiddenConversationCount, COMMENT_PAGE)} older conversation
444 {hiddenConversationCount === 1 ? "" : "s"} ({hiddenConversationCount} hidden)
445 </Button>
446 ) : null;
447 // Verdicts outside the visible comment window still count.
448 const reviewOutcomes = latestPullRequestReviewOutcomes(detail.comments, detail.commits);
449 // Host login casing varies; normalize to preserve verdicts and deduplicate reviewers.
450 const outcomeByLogin = new Map(
451 reviewOutcomes.flatMap((entry) =>
452 entry.actor ? [[reviewerKey(entry.actor.login), entry] as const] : [],
453 ),
454 );
455 // Hosts remove reviewed actors from requests; include submitted verdicts.
456 const reviewerEntries = [
457 ...detail.reviewers.map((actor) => ({
458 key: actor.login,
459 actor,
460 outcome: outcomeByLogin.get(reviewerKey(actor.login))?.outcome ?? null,
461 stale: outcomeByLogin.get(reviewerKey(actor.login))?.stale ?? false,
462 })),
463 ...reviewOutcomes
464 .filter(
465 (entry) =>
466 !detail.reviewers.some(
467 (actor) =>
468 entry.actor !== null && reviewerKey(actor.login) === reviewerKey(entry.actor.login),
469 ),
470 )
471 .map((entry) => ({
472 key: entry.key,
473 actor: entry.actor,
474 outcome: entry.outcome,
475 stale: entry.stale,
476 })),
477 ];
478
479 const openLink = useOpenLink(threadRef);
480 const openCheck = (url: string) => {
481 void openLink(url).catch((error: unknown) => {
482 console.error(error);
483 toastManager.add({ type: "error", title: "Unable to open check details" });
484 });
485 };
486
487 const update = useAtomCommand(pullRequestEnvironment.update, { reportFailure: false });
488 const updateComment = useAtomCommand(pullRequestEnvironment.updateComment, {
489 reportFailure: false,
490 });
491 const [bodyScope, setBodyScope] = useState<string | null>(null);
492 const [bodySaving, setBodySaving] = useState(false);
493 // Hosts can reuse comment ids across pull requests.
494 const [commentScope, setCommentScope] = useState<{
495 readonly pullRequest: string;
496 readonly commentId: string;
497 } | null>(null);
498 const [commentSaving, setCommentSaving] = useState(false);
499 const editingCommentId = commentScope?.pullRequest === detail.url ? commentScope.commentId : null;
500
501 const saveBody = async (body: string) => {
502 if (bodySaving) return;
503 setBodySaving(true);
504 const result = await update({ environmentId, input: { ...reference, body } });
505 setBodySaving(false);
506 if (result._tag === "Failure") {
507 toastManager.add({ type: "error", title: "Could not save the description" });
508 return;
509 }
510 setBodyScope(null);
511 onRefresh();
512 };
513
514 const commentEditing: CommentEditing = {
515 cwd: detail.workspaceRoot,
516 environmentId,
517 threadRef,
518 canEdit: (comment) => canEditPullRequestComment(detail, comment),
519 editingId: editingCommentId,
520 saving: commentSaving,
521 onEdit: (comment) =>
522 setCommentScope(comment === null ? null : { pullRequest: detail.url, commentId: comment.id }),
523 onSave: async (comment, body) => {
524 if (commentSaving || comment.kind === "review") return;
525 setCommentSaving(true);
526 const result = await updateComment({
527 environmentId,
528 input: { ...reference, commentId: comment.id, kind: comment.kind, body },
529 });
530 setCommentSaving(false);
531 if (result._tag === "Failure") {
532 toastManager.add({ type: "error", title: "Could not save the comment" });
533 return;
534 }
535 setCommentScope(null);
536 onRefresh();
537 },
538 };
539
540 const reactionBarFor = (comment: PullRequestComment) => (
541 <PullRequestReactionBar
542 className="ml-auto justify-end"
543 reactions={comment.reactions ?? []}
544 canReact={detail.capabilities.reactions === true}
545 subjectId={comment.id}
546 environmentId={environmentId}
547 reference={reference}
548 onRefresh={onRefresh}
549 />
550 );
551
552 const renderCommentCard = (
553 comment: PullRequestComment,
554 thread: PullRequestReviewThread | undefined,
555 { reply = false }: { reply?: boolean } = {},
556 ) => {
557 const body = visibleBody(comment.body);
558 const outcome = pullRequestReviewOutcome(comment.reviewState);
559 const finding: PullRequestFinding | null =
560 reply ||
561 (comment.kind !== "review" && comment.kind !== "review-comment") ||
562 outcome === "approved"
563 ? null
564 : thread === undefined
565 ? body === null
566 ? null
567 : { kind: "comment", comment }
568 : { kind: "thread", thread };
569 return (
570 <article
571 key={`${detail.url}:${comment.id}`}
572 className="group rounded-lg border border-border/60 bg-background [contain-intrinsic-block-size:160px] [content-visibility:auto]"
573 >
574 <div className="flex flex-wrap items-baseline gap-2 rounded-t-lg bg-muted/25 px-3 py-2.5">
575 <div className="flex min-w-0 flex-1 flex-wrap items-baseline gap-2 text-xs text-muted-foreground">
576 <CommentIdentity comment={comment} detail={detail} />
577 {outcome ? (
578 <PullRequestReviewOutcomeBadge outcome={outcome} />
579 ) : comment.reviewState ? (
580 <span>{reviewStateLabel(comment.reviewState)}</span>
581 ) : null}
582 </div>
583 {onFixFinding && finding ? (
584 <Button
585 size="xs"
586 variant="ghost"
587 className="shrink-0"
588 disabled={pendingFinding !== null && pendingFinding !== undefined}
589 onClick={() => onFixFinding(finding)}
590 >
591 <span className="inline-flex items-baseline gap-1">
592 <HammerIcon className="size-3 self-center" />
593 <span>
594 {pendingFinding === pullRequestFindingKey(finding)
595 ? "Preparing..."
596 : fixFindingLabel}
597 </span>
598 </span>
599 </Button>
600 ) : null}
601 {reactionBarFor(comment)}
602 </div>
603 {reply ? null : (
604 <div className="px-3">
605 <CommentLocation comment={comment} thread={thread} />
606 </div>
607 )}
608 {body === null && !commentEditing.canEdit(comment) ? null : (
609 <CommentBody className="px-3 py-3" comment={comment} editing={commentEditing} />
610 )}
611 </article>
612 );
613 };
614
615 const renderItem = (item: PullRequestConversationItem) => {
616 const comment = item.kind === "comment" ? item.comment : item.root;
617 const thread = item.kind === "thread" ? item.thread : undefined;
618 const replies =
619 item.kind === "thread" && item.replies.length > 0 ? (
620 <div className="ml-4 space-y-2 border-l-2 border-border/60 pl-3">
621 {item.replies.map((reply) => renderCommentCard(reply, undefined, { reply: true }))}
622 </div>
623 ) : null;
624 const moreReplies =
625 item.kind === "thread" && item.hasMoreReplies ? <PullRequestMoreReplies {...item} /> : null;
626 if (isPullRequestCommentFinished(comment, thread)) {
627 return (
628 <CollapsedComment
629 key={`${detail.url}:${item.kind}:${item.id}`}
630 comment={comment}
631 editing={commentEditing}
632 detail={detail}
633 thread={thread}
634 label={thread?.isResolved ? "Resolved" : "Review dismissed"}
635 body={visibleBody(comment.body)}
636 replyCount={item.kind === "thread" ? item.replies.length + item.moreReplies : 0}
637 replies={replies}
638 moreReplies={moreReplies}
639 reactionBar={reactionBarFor(comment)}
640 />
641 );
642 }
643 if (item.kind === "comment") return renderCommentCard(comment, undefined);
644 return (
645 <div key={`${detail.url}:thread:${item.id}`} className="space-y-2">
646 {renderCommentCard(comment, thread)}
647 {replies}
648 {moreReplies}
649 </div>
650 );
651 };
652
653 return (
654 <div ref={scrollerRef} className="h-full overflow-y-auto" data-pull-request-summary-scroll>
655 <section className="px-4 pt-2.5 pb-1">
656 <div className="space-y-2">
657 <MetaRow icon={<UsersIcon className="size-3.5" />} label="Reviewers">
658 <span className="flex min-w-0 flex-wrap items-center gap-1.5">
659 {reviewerEntries.length === 0 ? (
660 <span className="text-muted-foreground">None</span>
661 ) : (
662 <span className="flex items-center -space-x-1">
663 {reviewerEntries.map((entry) => {
664 const login = entry.actor?.login ?? "ghost";
665 const named =
666 entry.actor?.name && entry.actor.name !== login
667 ? `${entry.actor.name} (@${login})`
668 : login;
669 return (
670 <Tooltip key={entry.key}>
671 <TooltipTrigger
672 render={
673 <span
674 className={cn(
675 "relative rounded-full hover:z-10",
676 entry.outcome
677 ? pullRequestReviewOutcomeRingClassName(
678 entry.outcome,
679 entry.stale,
680 )
681 : undefined,
682 )}
683 />
684 }
685 >
686 <PullRequestActorLabel
687 actor={entry.actor}
688 tooltip={false}
689 variant="avatar"
690 />
691 {entry.outcome ? (
692 <span className="sr-only">
693 {entry.stale
694 ? pullRequestReviewOutcomeStaleLabel(entry.outcome)
695 : pullRequestReviewOutcomeLabel(entry.outcome)}
696 </span>
697 ) : null}
698 </TooltipTrigger>
699 <TooltipPopup side="bottom">
700 {entry.outcome
701 ? `${named}: ${
702 entry.stale
703 ? pullRequestReviewOutcomeStaleLabel(entry.outcome)
704 : pullRequestReviewOutcomeLabel(entry.outcome)
705 }`
706 : named}
707 </TooltipPopup>
708 </Tooltip>
709 );
710 })}
711 </span>
712 )}
713 {/* Azure DevOps accepts reviewers but cannot list candidates. */}
714 {detail.capabilities.reviewers.request &&
715 detail.capabilities.reviewers.listCandidates ? (
716 <PullRequestReviewerPicker
717 environmentId={environmentId}
718 reference={reference}
719 allowed={detail.viewerPermissions.requestReviewers}
720 />
721 ) : null}
722 </span>
723 </MetaRow>
724 {detail.labels.length > 0 || detail.capabilities.labels === true ? (
725 <MetaRow icon={<TagIcon className="size-3.5" />} label="Labels">
726 <span className="flex min-w-0 flex-wrap items-center gap-1">
727 {detail.labels.length === 0 ? (
728 <span className="text-muted-foreground">None</span>
729 ) : (
730 detail.labels.map((label) => (
731 <PullRequestLabelChip
732 key={label.name}
733 label={label}
734 size="default"
735 className="max-w-48"
736 />
737 ))
738 )}
739 {detail.capabilities.labels === true ? (
740 <PullRequestLabelPicker
741 environmentId={environmentId}
742 reference={reference}
743 allowed={detail.viewerPermissions.labels !== false}
744 />
745 ) : null}
746 </span>
747 </MetaRow>
748 ) : null}
749 </div>
750 </section>
751
752 <Section key={`description:${detail.url}`} title="Description" keepMounted>
753 <div className="group">
754 {bodyScope === detail.url ? (
755 <PullRequestMarkdownEditor
756 allowEmpty
757 value={detail.body}
758 cwd={detail.workspaceRoot}
759 environmentId={environmentId}
760 threadRef={threadRef}
761 label={`${capitalizeTerm(terminology.singular)} description`}
762 placeholder={`Describe this ${terminology.singular}`}
763 saving={bodySaving}
764 onSave={(body) => void saveBody(body)}
765 onCancel={() => setBodyScope(null)}
766 />
767 ) : (
768 <div className="flex items-start gap-1">
769 <PullRequestMarkdown
770 className="min-w-0 flex-1"
771 text={detail.body.trim().length > 0 ? detail.body : "_No description provided._"}
772 cwd={detail.workspaceRoot}
773 environmentId={environmentId}
774 threadRef={threadRef}
775 />
776 {canEditPullRequestChangeRequest(detail) ? (
777 <PullRequestEditButton
778 aria-label="Edit description"
779 onClick={() => setBodyScope(detail.url)}
780 />
781 ) : null}
782 </div>
783 )}
784 </div>
785 </Section>
786
787 <Section key={`checks:${detail.url}`} title="Checks" defaultOpen={false}>
788 {checksStale ? (
789 <div className="flex items-center gap-2 text-xs text-muted-foreground">
790 <span>Check details are out of date.</span>
791 <Button size="xs" variant="ghost" onClick={onRefreshChecks}>
792 Refresh
793 </Button>
794 </div>
795 ) : detail.checks.length === 0 ? (
796 <p className="text-xs text-muted-foreground">No checks reported.</p>
797 ) : (
798 detail.checks.map(
799 (
800 check,
801 index,
802 ) => /* oxlint-disable react/no-array-index-key -- Check names and URLs can repeat; these status rows have no local state. */ {
803 const finding = { kind: "check", check } as const;
804 const failing = check.status === "failure" || check.status === "cancelled";
805 return (
806 <div
807 key={`${index}:${check.name}:${check.url ?? ""}`}
808 className="group flex items-center gap-2 rounded-md pr-1 hover:bg-accent/60"
809 >
810 <button
811 type="button"
812 disabled={!check.url}
813 onClick={() => check.url && openCheck(check.url)}
814 className={cn(
815 "flex min-w-0 flex-1 items-start gap-2 rounded-md px-2 py-2 text-left text-xs leading-5 [&>svg]:mt-0.5",
816 check.url ? "cursor-pointer" : "cursor-default",
817 )}
818 >
819 <PullRequestCheckStatusIcon status={check.status} />
820 <span className="min-w-0 flex-1 wrap-anywhere">{check.name}</span>
821 <span className="shrink-0 text-muted-foreground">
822 {pullRequestCheckStatusLabel(check)}
823 </span>
824 </button>
825 {onFixFinding && failing ? (
826 <Button
827 size="xs"
828 variant="ghost"
829 className="shrink-0"
830 disabled={pendingFinding !== null && pendingFinding !== undefined}
831 onClick={() => onFixFinding(finding)}
832 >
833 <HammerIcon className="size-3" />
834 {pendingFinding === pullRequestFindingKey(finding)
835 ? "Preparing..."
836 : fixCheckLabel}
837 </Button>
838 ) : null}
839 </div>
840 );
841 } /* oxlint-enable react/no-array-index-key */,
842 )
843 )}
844 </Section>
845
846 <Section
847 title={`Comments (${detail.commentCount})`}
848 actions={
849 <div className="flex shrink-0 items-center gap-1">
850 <Menu>
851 <MenuTrigger
852 render={<Button size="xs" variant="ghost-muted" />}
853 aria-label="Filter comments"
854 >
855 <ListFilterIcon aria-hidden className="size-3" />
856 {filteredOutCount > 0 ? `${filteredOutCount} hidden` : "Filter"}
857 </MenuTrigger>
858 <MenuPopup align="end">
859 <MenuGroup>
860 <MenuGroupLabel>Show</MenuGroupLabel>
861 <MenuCheckboxItem
862 checked={commentFilter.bots}
863 closeOnClick={false}
864 onCheckedChange={(bots) => setCommentFilter((value) => ({ ...value, bots }))}
865 >
866 Bot comments
867 </MenuCheckboxItem>
868 <MenuCheckboxItem
869 checked={commentFilter.resolved}
870 closeOnClick={false}
871 onCheckedChange={(resolved) =>
872 setCommentFilter((value) => ({ ...value, resolved }))
873 }
874 >
875 Resolved or dismissed
876 </MenuCheckboxItem>
877 </MenuGroup>
878 </MenuPopup>
879 </Menu>
880 <Button
881 size="xs"
882 variant="ghost-muted"
883 aria-label={
884 commentOrder === "newest"
885 ? "Show oldest comments first"
886 : "Show newest comments first"
887 }
888 onClick={() => setCommentOrder((value) => (value === "newest" ? "oldest" : "newest"))}
889 >
890 <ArrowDownUpIcon aria-hidden className="size-3" />
891 {commentOrder === "newest" ? "Newest first" : "Oldest first"}
892 </Button>
893 </div>
894 }
895 >
896 {activityPending ? (
897 <PullRequestConversationGhost terminology={terminology} />
898 ) : activityError ? (
899 <PullRequestActivityUnavailableState
900 compact
901 error={activityError}
902 term={terminology.singular}
903 onRetry={onRefresh}
904 />
905 ) : (
906 <>
907 {detail.commentsTruncated ? (
908 <p className="mb-2 rounded-md border border-warning/30 bg-warning-surface px-2 py-1.5 text-xs">
909 This conversation is only partially loaded. {commentCount} comment
910 {commentCount === 1 ? " is" : "s are"} loaded; open it on the host to read the rest.
911 </p>
912 ) : null}
913 {items.length === 0 ? (
914 <p className="py-2 text-xs text-muted-foreground">No comments yet.</p>
915 ) : filteredItems.length === 0 ? (
916 <p className="py-2 text-xs text-muted-foreground">
917 {filteredOutCount === 1
918 ? "The only comment is hidden by the filter."
919 : `All ${filteredOutCount} comments are hidden by the filter.`}
920 </p>
921 ) : (
922 <div className="space-y-3">
923 {commentOrder === "oldest" ? showOldestCommentsButton : null}
924 {visibleItems.map(renderItem)}
925 {commentOrder === "newest" ? showOldestCommentsButton : null}
926 {shownConversations > COMMENT_PAGE ? (
927 <Button
928 size="sm"
929 variant="ghost"
930 className="w-full"
931 onClick={() => setShown({ url: detail.url, count: COMMENT_PAGE })}
932 >
933 Show only {COMMENT_PAGE} recent conversations
934 </Button>
935 ) : null}
936 </div>
937 )}
938 </>
939 )}
940 </Section>
941 </div>
942 );
943}