Watch
0
0
Fork
You've already forked hyperhive
0

swarm ui: a pull requests card on the reports tab

The reports tab gets a "pull requests" card under the issue report. It lists
the open PRs of every repo, or of one picked in a repo select, with the
columns a reviewer or merger filters on: author, labels, requested
reviewers, base branch, WIP (the forge's draft flag), approvals against the
base branch's protection rule, has all approvals, conflicts, protected base
and CI. Every column sorts, the small-set columns filter by picking values,
and the browser keeps the filters and the repo. No filter applies at first.

swarm-controller resolves each row so the page makes no calls of its own:
GET /api/pr-report and GET /api/repos/{org}/{repo}/pr-report. The required
approvals come from the first matching branch protection rule (an
unprotected base asks for none); an approval counts when it is the
reviewer's latest decision, on the current head, neither stale nor
dismissed and official.

A free-text table cell gets a minimum width, so a table with many columns
scrolls sideways instead of wrapping a title to a word a line.
This commit is contained in:
iris 2026-11-07 10:06:59 +01:00 • committed by mara
commit f633963b77

View file

@ -0,0 +1,62 @@
// Pure pieces of the PR report: the row the controller returns, the report
// URL for a repo filter, and the words its flag columns filter on. Kept out of
// the page so the cases are unit tested.
/** One open pull request, as `GET /api/pr-report` returns it. */
export interface PrReportRow {
/** `owner/name`. */
repo: string;
number: number;
title: string;
html_url: string | null;
author: string | null;
labels: string[];
assignees: string[];
requested_reviewers: string[];
base_branch: string;
head_branch: string;
created_unix: number | null;
updated_unix: number | null;
/** The forge's draft flag. */
wip: boolean;
has_conflicts: boolean;
/** The base branch has a branch protection rule. */
targets_protected_branch: boolean;
required_approvals: number;
approvals: number;
/** Reviewers whose latest review asks for changes. */
changes_requested: number;
/** `null` when the head has no commit status. */
ci: "success" | "pending" | "failure" | null;
}
/** The report URL for a repo filter. The path parts are encoded, so a name
* with `?`, `#` or `%` stays one path segment. A filter without a slash is
* not a repo, so it reads as all repos. */
export function prReportUrl(repoFilter: string): string {
const i = repoFilter.indexOf("/");
if (i < 0) return "/api/pr-report";
const org = encodeURIComponent(repoFilter.slice(0, i));
const name = encodeURIComponent(repoFilter.slice(i + 1));
return `/api/repos/${org}/${name}/pr-report`;
}
/** What a flag column offers as filter values. */
export function yesNo(flag: boolean): string {
return flag ? "yes" : "no";
}
/** The approvals meet the base branch's rule. An unprotected base asks for
* none, so its PRs have them all. */
export function hasAllApprovals(row: PrReportRow): boolean {
return row.approvals >= row.required_approvals;
}
/** 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 {
if (!row.targets_protected_branch || row.required_approvals === 0) {
return row.approvals > 0 ? `${row.approvals}` : "—";
}
return `${row.approvals}/${row.required_approvals}`;
}