Item page: real file count, discussion, timeline and readable verdicts

The item API returns changed_files, closed/merged times and the merger; the
page shows the file count, leaves out Checks and Mergeable when the mirror has
no data, lists GitHub comments and reviews, adds opened/merged/closed to the
timeline, and spells out topics and scored reasons.
This commit is contained in:
aiongg committed 2026-11-02 19:00:28 +00:00
1 parent 37fa931f97
commit 49d719f3fa
5 files changed
+142 -29

No files matched your search

+5 -2
View File
@@ -59,8 +59,8 @@ function trackedOnly(db: DatabaseSync, repo: string): void {
type ItemRow = {
repo: string; number: number; kind: string; state: string; title: string | null; body: string | null; author: string | null;
created_at: string | null; updated_at: string | null; labels: string | null; additions: number | null; deletions: number | null;
mergeable: string | null; ci_state: string | null;
created_at: string | null; updated_at: string | null; labels: string | null; additions: number | null; deletions: number | null; changed_files: number | null;
mergeable: string | null; ci_state: string | null; closed_at: string | null; merged_at: string | null; merged_by: string | null;
};
function item(db: DatabaseSync, req: Req): Item {
@@ -88,10 +88,13 @@ function item(db: DatabaseSync, req: Req): Item {
title: it.title ?? "", body: it.body ?? "", state: itemState(it.state), author: it.author ?? "",
tier: TIER[c?.tier ?? "not"] ?? "not", authorMerged: c?.merged ?? 0, authorClosedUnmerged: c?.closed ?? 0,
additions: it.additions ?? 0, deletions: it.deletions ?? 0,
changedFiles: it.kind === "pr" ? it.changed_files : null,
// The mirror stores only the rollup state and the counts, not per-file or per-check rows.
files: [], ciChecks: [],
ci: it.kind === "pr" ? (CI[it.ci_state ?? ""] ?? "none") : "none",
mergeable: MERGEABLE[it.mergeable ?? ""] ?? "unknown",
labels, createdAt: it.created_at ?? "", updatedAt: it.updated_at ?? "",
closedAt: it.closed_at, mergedAt: it.merged_at, mergedBy: it.merged_by,
related: relatedOf(db, repo, n), classifications: classificationsOf(db, repo, n),
stages: stages.map((s) => ({ ...s, by: s.by ?? "" })),
comments: comments.map((x) => ({ ...x, author: x.author ?? "", body: x.body ?? "" })),
+3
View File
@@ -42,6 +42,7 @@ before(async () => {
ins.run("photocraft", 4, "issue", "OPEN", "Crash on save", "d", "dave", now, now, null);
ins.run("photocraft", 5, "issue", "OPEN", "Wave filter missing", "e", "erin", now, now, null);
ins.run("untracked-repo", 6, "pr", "OPEN", "Add wave filter elsewhere", "f", "frank", now, now, null);
db.prepare("UPDATE items SET additions = 40, deletions = 3, changed_files = 7 WHERE repo = 'photocraft' AND number = 1").run();
db.prepare("INSERT INTO comments (repo, number, id, kind, author, created_at, body) VALUES ('photocraft', 1, 'c1', 'comment', 'alice', ?, 'looks good')").run(now);
db.prepare("INSERT INTO classifications (repo, number, classifier, run_id, at, type_label, want, reason) VALUES ('photocraft', 1, 'haiku', 'r1', ?, 'small extra', 'yes', 'adds a filter')").run(now);
ask(db, [P1, P2, F3, P4].map((id) => {
@@ -130,6 +131,8 @@ describe("api", () => {
assert.equal((await (await signedIn("maint")).get<User>("/api/me")).role, "viewer");
const it = await boss.get<Item>("/api/items/photocraft/1");
assert.equal(it.body, "<script>x</script> body");
assert.deepEqual([it.changedFiles, it.additions, it.deletions], [7, 40, 3]);
assert.equal((await boss.get<Item>("/api/items/photocraft/4")).changedFiles, null);
assert.deepEqual(it.comments.map((c) => c.body), ["looks good"]);
assert.deepEqual(it.decisionIds, [P1]);
assert.deepEqual(it.related.map((r) => [r.number, r.relation]), [[5, "fixes"]]);
+4
View File
@@ -720,6 +720,7 @@ export function itemFor(repo: string, number: number): Item {
authorClosedUnmerged: closedUn,
additions: s.size?.[0] ?? 0,
deletions: s.size?.[1] ?? 0,
changedFiles: isIssue ? null : filesFor(s).length,
files: filesFor(s),
ci,
ciChecks: checks,
@@ -727,6 +728,9 @@ export function itemFor(repo: string, number: number): Item {
labels: isIssue ? ["bug"] : ["enhancement", ...(s.kind === "scope" ? ["needs-scope"] : [])],
createdAt: iso(s.ageH * H + 26 * H),
updatedAt: iso(s.ageH * H - 2 * H),
closedAt: null,
mergedAt: null,
mergedBy: null,
related: s.related ?? [],
classifications: d.classifications,
stages: stagesFor(s, d),
+7
View File
@@ -156,13 +156,20 @@ export interface Item extends ItemRef {
authorClosedUnmerged: number;
additions: number;
deletions: number;
/** PRs: how many files the PR changes, from the mirror; null when unknown. */
changedFiles: number | null;
/** Per-file changes; empty when the mirror has none. */
files: ChangedFile[];
/** "none" also when the mirror has no check data for the item. */
ci: CiState;
ciChecks: { name: string; state: CiState; minutes: number }[];
mergeable: Mergeable;
labels: string[];
createdAt: string;
updatedAt: string;
closedAt: string | null;
mergedAt: string | null;
mergedBy: string | null;
related: RelatedItem[];
classifications: Classification[];
stages: StageEntry[];
+123 -27
View File
@@ -13,10 +13,11 @@ import {
FlagIcon,
CircleCheckIcon,
CircleSlashIcon,
MessageSquareIcon,
type LucideIcon,
} from "lucide-react";
import { useQuery } from "../../api/client";
import type { CiState, Classification, Item, Stage, Tier } from "../../api/types";
import type { CiState, Classification, Item, ItemComment, Stage, Tier } from "../../api/types";
import type { FeatureModule, ViewProps } from "../../registry/types";
import { Slot } from "../../registry/Slot";
import { Avatar } from "../../ui/Avatar";
@@ -91,6 +92,11 @@ function ItemMain({ params }: ViewProps) {
<Files it={it} />
</Section>
)}
{it.comments.length > 0 && (
<Section title="Discussion" aside={`${it.comments.length} ${it.comments.length === 1 ? "comment" : "comments"}`}>
<Discussion comments={it.comments} />
</Section>
)}
</div>
</div>
);
@@ -142,6 +148,9 @@ function Properties({ it }: { it: Item }) {
const total = it.additions + it.deletions;
const passing = it.ciChecks.filter((c) => c.state === "passing").length;
const [CiIcon, ciCls] = CI_ICON[it.ci];
// The mirror records checks and mergeability only for open PRs; without them the rows are left out.
const showCi = it.kind === "pr" && it.ci !== "none";
const showMergeable = it.kind === "pr" && it.state === "open" && it.mergeable !== "unknown";
return (
<dl className="mt-4 grid grid-cols-[96px_1fr] gap-x-4 text-sm md:grid-cols-[96px_1fr_96px_1fr]">
<Prop label="Author">
@@ -157,28 +166,34 @@ function Properties({ it }: { it: Item }) {
<span className="code">
<span className="text-ok">+{num(it.additions)}</span> <span className="text-bad">−{num(it.deletions)}</span>
</span>
<span className="text-ink/60">{it.files.length} files</span>
{it.changedFiles !== null && (
<span className="text-ink/60">
{num(it.changedFiles)} {it.changedFiles === 1 ? "file" : "files"}
</span>
)}
<Badge>{sizeBucket(total)}</Badge>
</>
) : (
<span className="text-ink/60">Issue</span>
)}
</Prop>
<Prop label="Checks">
<span className={cn("inline-flex items-center gap-1 font-medium", ciCls)}>
<CiIcon /> {it.ci === "none" ? "No checks" : it.ci[0].toUpperCase() + it.ci.slice(1)}
</span>
{it.ciChecks.length > 0 && (
<span className="text-ink/55">
{passing} of {it.ciChecks.length} passed
{showCi && (
<Prop label="Checks">
<span className={cn("inline-flex items-center gap-1 font-medium", ciCls)}>
<CiIcon /> {it.ci[0]!.toUpperCase() + it.ci.slice(1)}
</span>
)}
</Prop>
<Prop label="Mergeable">
<span className={cn("font-medium", it.mergeable === "clean" ? "text-ok" : it.mergeable === "conflicts" ? "text-bad" : "text-ink/55")}>
{it.mergeable === "clean" ? "No conflicts" : it.mergeable === "conflicts" ? "Has conflicts" : "Unknown"}
</span>
</Prop>
{it.ciChecks.length > 0 && (
<span className="text-ink/55">
{passing} of {it.ciChecks.length} passed
</span>
)}
</Prop>
)}
{showMergeable && (
<Prop label="Mergeable">
<span className={cn("font-medium", it.mergeable === "clean" ? "text-ok" : "text-bad")}>{it.mergeable === "clean" ? "No conflicts" : "Has conflicts"}</span>
</Prop>
)}
<Prop label="Labels">
{it.labels.map((l) => (
<Badge key={l}>{l}</Badge>
@@ -203,6 +218,29 @@ function agreement(cls: Classification[]) {
return n === cls.length ? "all agree on type" : `${n} of ${cls.length} agree on type`;
}
const likelihood = (p: number) => (p < 0.2 ? "unlikely" : p < 0.5 ? "possible" : p < 0.8 ? "likely" : "very likely");
const percent = (p: number) => `${Math.round(p * 100)}%`;
// Classifiers that score labels write "bugfix 0.84; security 0.03; needs decision 0.27":
// the chosen label's probability, then flag probabilities. Other reasons are prose.
function Reason({ reason }: { reason: string }) {
const parts = reason.split(";").map((x) => /^\s*([a-z][a-z -]*?)\s+(0(?:\.\d+)?|1(?:\.0+)?)\s*$/i.exec(x));
if (!parts.length || parts.some((m) => !m)) return <>{reason}</>;
const [label, ...flags] = parts.map((m) => ({ name: m![1]!, p: Number(m![2]) }));
return (
<>
<span>
{label!.name} ({percent(label!.p)})
</span>
{flags.length > 0 && (
<span className="block text-xs text-ink/55">
{flags.map((f) => `${f.name[0]!.toUpperCase()}${f.name.slice(1)}: ${likelihood(f.p)} (${percent(f.p)})`).join(" · ")}
</span>
)}
</>
);
}
const WANT: Record<string, string> = { yes: "text-ok", no: "text-bad", unclear: "text-warn" };
function Verdicts({ cls }: { cls: Classification[] }) {
@@ -223,7 +261,9 @@ function Verdicts({ cls }: { cls: Classification[] }) {
<span className="ml-auto text-xs text-ink/45">{ago(c.at)}</span>
</div>
{c.reference && <div className="mt-0.5 text-xs text-ink/55">Reference: {c.reference}</div>}
<p className="mt-1 text-sm text-ink/70">{c.reason}</p>
<div className="mt-1 text-sm text-ink/70">
<Reason reason={c.reason} />
</div>
</li>
))}
</ul>
@@ -232,8 +272,8 @@ function Verdicts({ cls }: { cls: Classification[] }) {
{ label: "Type", render: (c) => c.typeLabel, off: (c) => c.typeLabel !== typeMaj },
{ label: "Want", render: (c) => <span className={WANT[c.want]}>{c.want}</span>, off: (c) => c.want !== wantMaj },
{ label: "Reference", render: (c) => c.reference ?? <span className="text-ink/35">none</span> },
{ label: "Topics", render: (c) => c.topics },
{ label: "Reason", render: (c) => <span className="text-ink/70">{c.reason}</span> },
{ label: "Topics", render: (c) => (c.topics === "many" ? "several topics" : "one topic") },
{ label: "Reason", render: (c) => <span className="text-ink/70"><Reason reason={c.reason} /></span> },
];
return (
<div className="overflow-hidden rounded-md border border-line">
@@ -280,23 +320,79 @@ const STAGE: Record<Stage, [string, LucideIcon]> = {
"fixed-by-us": ["Fixed by us", CircleCheckIcon],
};
type Event = { label: string; Icon: LucideIcon; at: string; by: string; note: string | null };
// GitHub's own events from the mirror, merged with the pipeline's stages.
// A pipeline merge or close already says who did it, so GitHub's copy is left out.
function events(it: Item): Event[] {
const out: Event[] = [{ label: "Opened", Icon: it.kind === "pr" ? GitPullRequestIcon : CircleDotIcon, at: it.createdAt, by: it.author, note: null }];
for (const s of it.stages) {
const [label, Icon] = STAGE[s.stage];
out.push({ label, Icon, at: s.at, by: s.by, note: s.note });
}
const has = (st: Stage) => it.stages.some((s) => s.stage === st);
if (it.state === "merged" && it.mergedAt && !has("merged")) out.push({ label: "Merged", Icon: GitMergeIcon, at: it.mergedAt, by: it.mergedBy ?? "", note: null });
else if (it.state === "closed" && it.closedAt && !has("closed")) out.push({ label: "Closed", Icon: CircleSlashIcon, at: it.closedAt, by: "", note: null });
return out.filter((e) => e.at).sort((a, b) => Date.parse(a.at) - Date.parse(b.at));
}
function Timeline({ it }: { it: Item }) {
const evs = events(it);
return (
<ol className="relative">
<span className="absolute bottom-3 left-[11px] top-3 w-px bg-line-strong" aria-hidden />
{it.stages.map((s, i) => {
const last = i === it.stages.length - 1;
const [label, Icon] = STAGE[s.stage];
{evs.length > 1 && <span className="absolute bottom-3 left-[11px] top-3 w-px bg-line-strong" aria-hidden />}
{evs.map((e, i) => {
const last = i === evs.length - 1 && evs.length > 1;
return (
<li key={i} className="relative flex items-center gap-3 py-1.5">
<span className={cn("z-[1] flex size-6 shrink-0 items-center justify-center rounded-full border", last ? "border-warn/50 bg-warn/15 text-warn" : "border-line-strong bg-panel text-ink/55")}>
<Icon className="text-[12px]" />
<e.Icon className="text-[12px]" />
</span>
<span className="min-w-0 flex-1 text-sm">
<span className={cn(last ? "font-medium text-ink" : "text-ink/85")}>{label}</span> <span className="text-ink/55">by {s.by}</span>
{s.note && <span className="text-ink/45"> · {s.note}</span>}
<span className={cn(last ? "font-medium text-ink" : "text-ink/85")}>{e.label}</span>
{e.by && <span className="text-ink/55"> by {e.by}</span>}
{e.note && <span className="text-ink/45"> · {e.note}</span>}
</span>
<span className="shrink-0 text-xs text-ink/45">{ago(s.at)} ago</span>
<span className="shrink-0 text-xs text-ink/45">{ago(e.at)} ago</span>
</li>
);
})}
</ol>
);
}
const REVIEW: Record<string, [string, Tone]> = {
APPROVED: ["approved", "ok"],
CHANGES_REQUESTED: ["requested changes", "bad"],
COMMENTED: ["reviewed", "neutral"],
DISMISSED: ["review dismissed", "neutral"],
};
// GitHub comments and reviews, oldest first. Bodies are untrusted: the same Markdown renderer as the description.
function Discussion({ comments }: { comments: ItemComment[] }) {
return (
<ol className="space-y-3">
{comments.map((c) => {
const review = c.kind === "review" ? (REVIEW[c.reviewState ?? ""] ?? REVIEW.COMMENTED!) : null;
return (
<li key={c.id} className="overflow-hidden rounded-md border border-line">
<div className="flex flex-wrap items-center gap-x-2 gap-y-1 border-b border-line bg-ink/[0.03] px-3 py-1.5 text-sm">
{c.author ? <Avatar login={c.author} size={18} /> : <MessageSquareIcon className="text-ink/40" />}
<span className="font-medium">{c.author || "ghost"}</span>
{review && <Badge tone={review[1]}>{review[0]}</Badge>}
<span className="ml-auto text-xs text-ink/45" title={c.at}>
{c.at ? ago(c.at, false) : ""}
</span>
</div>
<div className="px-3 py-2">
{c.body.trim() ? (
<Collapsible lines={12}>
<Markdown source={c.body} />
</Collapsible>
) : (
<p className="text-sm text-ink/45">No text.</p>
)}
</div>
</li>
);
})}