Personal tooling for reviewing pull requests in cslib-community/cslib-frontier.
- Node 26 or later, which runs the TypeScript files directly. There is no build step and
there are no runtime dependencies, so the scripts run without
npm install. - The
ghCLI, signed in (gh auth status).
To work on the scripts, run npm install once for the development tools,
Prettier and TypeScript. Before committing, format with
npm run format and check types with npm run typecheck. CI checks both.
node find-pr.ts
lists the open pull requests that are
- not drafts,
- not yours,
- targeting
main, - without any comment or review (so nobody has claimed them),
- not stacked on another open pull request, and
- green: every check finished without failing.
They are printed oldest first, as #number, author, size and title.
node find-pr.ts --first # just the one that has waited longest
node find-pr.ts --first --json # the same, as JSON
node find-pr.ts --order smallest --limit 5 # the five smallest
node find-pr.ts --author schoppmp --max-additions 1500
node find-pr.ts --title 'Crypto/LWE'
node find-pr.ts --explain # also say why each other one was rejected
node find-pr.ts --help
--allow-comments, --allow-stacked and --any-checks relax the corresponding criterion.
Two of the criteria are stricter than they sound:
- Not stacked is three tests. A pull request can target
mainand still be stacked, so the finder also rejects a description that says "stacked on", "merge that first" or "depends on #N", and a branch that contains the head commit of another open pull request. - Green requires that checks exist. A head with no checks at all, such as a workflow waiting for approval, is rejected.
node re-review-pr.ts
lists the open pull requests that are waiting for your second look. Each one is
- not a draft and not yours,
- one you gave a verdict on,
- answered: since your most recent verdict the head has moved and the author has commented,
- green, and
- not taken: nobody, you included, has a verdict that covers the current head, and nobody holds an unexpired claim on it.
It takes --first, --limit, --order, --author, --title, --json, --explain and
--any-checks as find-pr.ts does, and --allow-taken to relax the last criterion.
--explain lists only the rejected pull requests you commented on.
The repository moves fast, so a pull request that was listed can be approved or merged a few minutes later. Check again right before you claim one:
node re-review-pr.ts --pr 10095
judges that one pull request by the same criteria and says why. Its exit status is 0 when
the pull request qualifies and 1 when it does not, which includes a pull request that has
been merged or closed. With --json it prints number, qualifies and reason.
How the terms are read:
- A verdict is a line that starts with
APPROVEorREQUEST_CHANGES(bold or not), or a GitHub review that approves or requests changes. It is about the commit thatat <sha>on that line names, or else the commit the GitHub review was submitted on. - Your most recent verdict is the anchor. Your other comments and your
CLAIMlines do not make a pull request qualify, and commenting after the author's fix does not take it off the list. - The head has moved when the current head is not the commit your verdict is about. A verdict that names no commit falls back to dates: some commit must be dated after it.
- A verdict covers the current head when it is about the head commit, or names no commit and was given after the head was committed. An approval of an older head covers nothing, whoever gave it: a pull request you approved comes back when the author pushes and comments again.
Criteria are values that combine:
import { allOf, authoredBy, maxAdditions, reviewable } from "./lib/criteria.ts";
import { pickPullRequest } from "./lib/find.ts";
const small = reviewable.and(maxAdditions(1000), authoredBy("schoppmp").not());
const pr = await pickPullRequest({ criterion: small, order: "smallest" });
console.log(pr?.number, pr?.title);lib/criteria.ts: theCriterionclass, the combinatorsallOf,anyOfandnot, the built-in criteria, and the presetsreviewable,notStackedandawaitingReReview.lib/find.ts:findPullRequests,pickPullRequestandjudgePullRequests, which also returns the rejected pull requests with the reason, andjudgePullRequestfor one pull request by number.lib/pr.ts: thePullRequestclass,fetchOpenPullRequestsandfetchPullRequest.lib/report.ts: prints matches and rejections for the scripts.lib/gh.ts: the wrapper aroundgh.
A new criterion is a name and a function that returns a verdict:
import { Criterion } from "./lib/criteria.ts";
const touchesFewFiles = new Criterion("few files", (pr) => ({
pass: pr.changedFiles <= 5,
reason: `${pr.changedFiles} file(s)`,
}));allOf stops at the first failure, so put cheap criteria first. A criterion that calls
pr.remarks(), pr.checks(), pr.commits() or pr.activity() costs one gh call for each
pull request it is asked about.