Watch
0
0
Fork
You've already forked hyperhive
0

swarm ui: a diff column on the pull requests card, and "approved" as its header

The pull requests card gets a diff column, the lines a PR adds and removes
(`+120 −8`), sortable on the total. The controller takes the counts from the
forge's pull request list, so no call is added. The column that said "has all
approvals" is now headed "approved".
This commit is contained in:
iris 2026-11-07 10:46:02 +01:00 • committed by mara
commit 944fd5b726
3 changed files with 46 additions and 3 deletions

View file

@ -24,6 +24,8 @@ import { TableSkeleton } from "../ui/table/TableSkeleton.js";
import { ALL_REPOS, repoOptions } from "./issue-report-repo.js";
import {
approvalsText,
diffSize,
diffText,
hasAllApprovals,
prReportUrl,
yesNo,
@ -124,7 +126,7 @@ const COLUMNS: TableColumn<PrReportRow>[] = [
},
{
key: "approved",
header: "has all approvals",
header: "approved",
render: (r) =>
hasAllApprovals(r) ? <Badge tone="positive" value="yes" /> : "no",
sortBy: (r) => Number(hasAllApprovals(r)),
@ -156,6 +158,12 @@ const COLUMNS: TableColumn<PrReportRow>[] = [
filterValues: (r) => [r.ci ?? "none"],
filterMode: "multiselect",
},
{
key: "diff",
header: "diff",
render: (r) => diffText(r),
sortBy: (r) => diffSize(r),
},
{
key: "updated",
header: "updated",

View file

@ -17,6 +17,9 @@ export interface PrReportRow {
head_branch: string;
created_unix: number | null;
updated_unix: number | null;
/** Lines the PR adds and removes. */
additions: number | null;
deletions: number | null;
/** The forge's draft flag. */
wip: boolean;
has_conflicts: boolean;
@ -52,6 +55,18 @@ export function hasAllApprovals(row: PrReportRow): boolean {
return row.approvals >= row.required_approvals;
}
/** The diff size cell: lines added and removed, `+120 −8`. A count the forge
* did not give reads as a dash. */
export function diffText(row: PrReportRow): string {
if (row.additions === null && row.deletions === null) return "—";
return `+${row.additions ?? 0} −${row.deletions ?? 0}`;
}
/** What the diff column sorts on: lines changed in all. */
export function diffSize(row: PrReportRow): number {
return (row.additions ?? 0) + (row.deletions ?? 0);
}
/** The approvals cell: how many of the rule's approvals the PR has, or a dash
* when its base branch asks for none. */
export function approvalsText(row: PrReportRow): string {

View file

@ -3,6 +3,8 @@ import assert from "node:assert/strict";
import { test } from "node:test";
import {
approvalsText,
diffSize,
diffText,
hasAllApprovals,
prReportUrl,
yesNo,
@ -52,6 +54,15 @@ test("an unprotected base, or a rule asking for none, shows only what it has", (
);
});
test("the diff reads as lines added and removed, and sorts on both", () => {
assert.equal(diffText({ additions: 120, deletions: 8 }), "+120 −8");
assert.equal(diffText({ additions: 0, deletions: 3 }), "+0 −3");
assert.equal(diffText({ additions: 5, deletions: null }), "+5 −0");
assert.equal(diffText({ additions: null, deletions: null }), "—");
assert.equal(diffSize({ additions: 120, deletions: 8 }), 128);
assert.equal(diffSize({ additions: null, deletions: null }), 0);
});
test("a PR has all approvals when it meets the rule, and an unprotected base always does", () => {
assert.equal(hasAllApprovals(row({})), false);
assert.equal(hasAllApprovals(row({ approvals: 2 })), true);