diff --git a/src/dash/api/index.ts b/src/dash/api/index.ts index 2ba57bd2..9d5a946d 100644 --- a/src/dash/api/index.ts +++ b/src/dash/api/index.ts @@ -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 ?? "" })), diff --git a/test/api.test.ts b/test/api.test.ts index 4c8226a2..d463cfa0 100644 --- a/test/api.test.ts +++ b/test/api.test.ts @@ -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("/api/me")).role, "viewer"); const it = await boss.get("/api/items/photocraft/1"); assert.equal(it.body, " body"); + assert.deepEqual([it.changedFiles, it.additions, it.deletions], [7, 40, 3]); + assert.equal((await boss.get("/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"]]); diff --git a/web/src/api/mock/fixtures.ts b/web/src/api/mock/fixtures.ts index db262bda..ffdcddd0 100644 --- a/web/src/api/mock/fixtures.ts +++ b/web/src/api/mock/fixtures.ts @@ -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), diff --git a/web/src/api/types.ts b/web/src/api/types.ts index c697f35e..9d20d5ae 100644 --- a/web/src/api/types.ts +++ b/web/src/api/types.ts @@ -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[]; diff --git a/web/src/modules/item/index.tsx b/web/src/modules/item/index.tsx index 3229932b..4df22375 100644 --- a/web/src/modules/item/index.tsx +++ b/web/src/modules/item/index.tsx @@ -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) { )} + {it.comments.length > 0 && ( +
+ +
+ )} ); @@ -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 (
@@ -157,28 +166,34 @@ function Properties({ it }: { it: Item }) { +{num(it.additions)} −{num(it.deletions)} - {it.files.length} files + {it.changedFiles !== null && ( + + {num(it.changedFiles)} {it.changedFiles === 1 ? "file" : "files"} + + )} {sizeBucket(total)} ) : ( Issue )} - - - {it.ci === "none" ? "No checks" : it.ci[0].toUpperCase() + it.ci.slice(1)} - - {it.ciChecks.length > 0 && ( - - {passing} of {it.ciChecks.length} passed + {showCi && ( + + + {it.ci[0]!.toUpperCase() + it.ci.slice(1)} - )} - - - - {it.mergeable === "clean" ? "No conflicts" : it.mergeable === "conflicts" ? "Has conflicts" : "Unknown"} - - + {it.ciChecks.length > 0 && ( + + {passing} of {it.ciChecks.length} passed + + )} + + )} + {showMergeable && ( + + {it.mergeable === "clean" ? "No conflicts" : "Has conflicts"} + + )} {it.labels.map((l) => ( {l} @@ -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 ( + <> + + {label!.name} ({percent(label!.p)}) + + {flags.length > 0 && ( + + {flags.map((f) => `${f.name[0]!.toUpperCase()}${f.name.slice(1)}: ${likelihood(f.p)} (${percent(f.p)})`).join(" · ")} + + )} + + ); +} + const WANT: Record = { yes: "text-ok", no: "text-bad", unclear: "text-warn" }; function Verdicts({ cls }: { cls: Classification[] }) { @@ -223,7 +261,9 @@ function Verdicts({ cls }: { cls: Classification[] }) { {ago(c.at)} {c.reference &&
Reference: {c.reference}
} -

{c.reason}

+
+ +
))} @@ -232,8 +272,8 @@ function Verdicts({ cls }: { cls: Classification[] }) { { label: "Type", render: (c) => c.typeLabel, off: (c) => c.typeLabel !== typeMaj }, { label: "Want", render: (c) => {c.want}, off: (c) => c.want !== wantMaj }, { label: "Reference", render: (c) => c.reference ?? none }, - { label: "Topics", render: (c) => c.topics }, - { label: "Reason", render: (c) => {c.reason} }, + { label: "Topics", render: (c) => (c.topics === "many" ? "several topics" : "one topic") }, + { label: "Reason", render: (c) => }, ]; return (
@@ -280,23 +320,79 @@ const STAGE: Record = { "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 (
    - - {it.stages.map((s, i) => { - const last = i === it.stages.length - 1; - const [label, Icon] = STAGE[s.stage]; + {evs.length > 1 && } + {evs.map((e, i) => { + const last = i === evs.length - 1 && evs.length > 1; return (
  1. - + - {label} by {s.by} - {s.note && · {s.note}} + {e.label} + {e.by && by {e.by}} + {e.note && · {e.note}} - {ago(s.at)} ago + {ago(e.at)} ago +
  2. + ); + })} +
+ ); +} + +const REVIEW: Record = { + 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 ( +
    + {comments.map((c) => { + const review = c.kind === "review" ? (REVIEW[c.reviewState ?? ""] ?? REVIEW.COMMENTED!) : null; + return ( +
  1. +
    + {c.author ? : } + {c.author || "ghost"} + {review && {review[0]}} + + {c.at ? ago(c.at, false) : ""} + +
    +
    + {c.body.trim() ? ( + + + + ) : ( +

    No text.

    + )} +
  2. ); })}