import { IconCheck, IconX, IconClock } from "@tabler/icons-react"; import { Badge } from "@kandev/ui/badge"; import type { PRReview } from "@/lib/types/github"; import { CollapsibleSection, AddToContextButton, AuthorAvatar, AuthorLink, formatTimeAgo, } from "./pr-shared"; function ReviewStateIcon({ state }: { state: string }) { if (state === "APPROVED") return ; if (state === "CHANGES_REQUESTED") return ; return ; } function reviewStateLabel(state: string): string { const labels: Record = { APPROVED: "Approved", CHANGES_REQUESTED: "Changes Requested", COMMENTED: "Commented", PENDING: "Pending", DISMISSED: "Dismissed", }; return labels[state] ?? state; } export function ReviewStateBadge({ state }: { state: string }) { if (!state) return null; const styles: Record = { approved: "bg-green-100 text-green-700 dark:bg-green-900/30 dark:text-green-400", changes_requested: "bg-red-100 text-red-700 dark:bg-red-900/30 dark:text-red-400", pending: "bg-yellow-100 text-yellow-700 dark:bg-yellow-900/30 dark:text-yellow-400", }; const labelMap: Record = { approved: "Approved", changes_requested: "Changes requested", pending: "Review pending", }; return ( {labelMap[state] ?? state} ); } function buildReviewMessage(review: PRReview, prUrl: string): string { const parts = [`Review from **${review.author}** (${review.state}):`]; if (review.body) parts.push(review.body); parts.push(`PR: ${prUrl}`); parts.push("Please address this review feedback."); return parts.join("\n\n"); } function buildAllReviewsMessage(reviews: PRReview[], prUrl: string): string { const parts = ["### All PR Reviews", ""]; for (const r of reviews) { parts.push(`**${r.author}** — ${reviewStateLabel(r.state)}`); if (r.body) parts.push(r.body); parts.push(""); } parts.push(`PR: ${prUrl}`); parts.push("Please address the review feedback above."); return parts.join("\n"); } function formatReviewSummary(reviews: PRReview[]): string { const approved = reviews.filter((r) => r.state === "APPROVED").length; const changes = reviews.filter((r) => r.state === "CHANGES_REQUESTED").length; const parts: string[] = []; if (approved > 0) parts.push(`${approved} approved`); if (changes > 0) parts.push(`${changes} changes requested`); const other = reviews.length - approved - changes; if (other > 0) parts.push(`${other} other`); return parts.join(", "); } export function ReviewsSection({ reviews, prUrl, reviewState, reviewCount, pendingReviewCount, onAddAsContext, }: { reviews: PRReview[]; prUrl: string; reviewState: string; reviewCount: number; pendingReviewCount: number; onAddAsContext: (message: string) => void; }) { const summary = reviews.length > 0 ? ` \u2014 ${formatReviewSummary(reviews)}` : ""; const pendingText = pendingReviewCount > 0 ? ` (${pendingReviewCount} pending)` : ""; const subtitle = reviewState ? (
Overall: {pendingText && {pendingText}}
) : null; return ( onAddAsContext(buildAllReviewsMessage(reviews, prUrl))} addAllLabel="Add all reviews to chat context" > {reviews.length === 0 && (

No reviews yet

)} {reviews.map((review) => (
{reviewStateLabel(review.state)} {formatTimeAgo(review.created_at)} {(review.state === "CHANGES_REQUESTED" || review.body) && ( onAddAsContext(buildReviewMessage(review, prUrl))} /> )}
{review.body && (

{review.body}

)}
))}
); }