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