import { escapeHtml } from "@kitajs/html"; import config from "../../config.ts"; import type { LabelRow, PatchCommentRow, PatchRow, RepositoryRow, } from "../../db/index.ts"; import { formatDateTime } from "../../lib/formatDate.ts"; import { displayName } from "../../lib/users.ts"; import type { SessionUser } from "../../middleware/session.ts"; import type { RenderedDiffFile } from "../../services/diffHighlight.ts"; import type { PatchMeta } from "../../services/git.ts"; import type { ApplyResult } from "../../services/patchCache.ts"; import { Avatar } from "../Avatar.tsx"; import { CommentThread } from "../CommentThread.tsx"; import { DateWithEdited } from "../DateWithEdited.tsx"; import { DiffView } from "../DiffView.tsx"; import { EditableTitle } from "../EditableTitle.tsx"; import { LabelBadges } from "../LabelBadges.tsx"; import { Layout } from "../layout.tsx"; import { ReactionBar, type ReactionCount } from "../ReactionBar.tsx"; import { RepoHeader } from "../repos/RepoHeader.tsx"; import { RepoNav } from "../repos/RepoNav.tsx"; interface PatchDetailProps { user: SessionUser | null; repo: RepositoryRow; patch: PatchRow & { author_username: string; author_avatar_version: number | null; author_name: string; author_email: string; }; descriptionHtml: string; applyResult: ApplyResult | null; files: RenderedDiffFile[]; tab: "conversation" | "changes"; patchMeta: PatchMeta; comments: (PatchCommentRow & { author_username: string; author_avatar_version: number | null; bodyHtml: string; })[]; reactions: ReactionCount[]; commentReactions: Map; patchLabels: LabelRow[]; repoLabels: LabelRow[]; } export function PatchDetail({ user, repo, patch, descriptionHtml, applyResult, files, tab, patchMeta, comments, reactions, commentReactions, patchLabels, repoLabels, }: PatchDetailProps) { const canEdit = user != null && (user.isAdmin || (user.id === patch.author_id && patch.status === "open")); const canManageLabels = user != null && (user.isAdmin || (repo.allow_user_labels === 1 && user.id === patch.author_id)); const baseUrl = `/${repo.name}/patches/${patch.number}`; const reactUrl = `${baseUrl}/react`; return (
#{patch.number} {patch.status} {canEdit && (
{user?.isAdmin && patch.status === "open" && applyResult?.status === "clean" && (
)} {patch.status === "open" && (
Update patch file
)} {user?.isAdmin && patch.status !== "merged" && (
)}
Delete
Permanently delete this patch?
)}
{/* Subview tabs */} {tab === "conversation" ? (
{/* Patch description */}
{displayName(patch.author_username)}
{canEdit && (
Edit Stop editing
)}
{canEdit && (
)}
{(descriptionHtml as "safe") || ( No description provided. )}
{/* Apply status */} {!!applyResult && (
{applyResult.status === "clean" ? "✓" : "✗"} {applyResult.status === "clean" ? "Applies cleanly" : "Has conflicts"}
{!!applyResult.output && (
                                            {applyResult.output}
                                        
)}
)}
) : (

{patchMeta.subject ? escapeHtml(patchMeta.subject) : "No commit message"}

{!!patchMeta.body && (
                                    {escapeHtml(patchMeta.body)}
                                
)}
Author {escapeHtml( `${patchMeta.author} <${patchMeta.email}>`, )}
Date
)}
); }