Skip to content

github

Roadmap entries 57 and 58: while arthur run runs, Arthur asks GitHub for the CI runs of the branches in play and emits ci-finished once per run attempt, and, when wakeOn names them, the reviews of open pull requests as pull-request-review; either wakes the coordinator when wakeOn names it, a passed run excepted. Nothing listens for GitHub: the plugin polls, so there is no endpoint to expose and no webhook secret. arthur ci <branch> tells why a branch’s run failed and reruns it once (arthur ci --help), arthur github reads and writes a project’s pull requests and issues (arthur github --help), a branch a review passed and main after a merge are pushed to origin, and a pruned job’s branch is deleted there (arthur github branch --help sweeps those left before).

plugins: [
orchestration({}),
projects({ folders: ["projects/shop"] }), // projects/shop/project.config.ts: projects.project({ prefix: "SH", repo: "git@github.com:acme/shop.git" }), github.project({ workflow: "ci.yml" })
github({
instances: [{ tokenEnv: "ARTHUR_GITHUB_TOKEN" }, { name: "acme", tokenEnv: "ARTHUR_GITHUB_ACME_TOKEN" }],
poll: { everySeconds: 120 },
wakeOn: ["ci-finished", "pull-request-review"],
}),
],

It needs projects in the list (requires), which sets up first.

  • instances: the GitHub accounts, at least one, each { name?, tokenEnv, apiUrl? }, at most one without a name.
  • name: a GitHub owner, user or organization, in lowercase (letters, digits, single dashes): the instance reads that owner’s repositories. Left out: the unnamed instance, which reads every repository whose owner no instance is named after.
  • tokenEnv: the variable holding the token. Make it a fine-grained personal access token whose “Repository access” is “Only select repositories”, the projects’ repositories and no other, with Actions: read, or Actions: read and write for arthur ci --rerun and github.cancel, and Pull requests: read for pull-request-review and arthur github pr list and pr get, or Pull requests: read and write for pr create, pr comment and pr close, and Issues: read for arthur github issue list and issue get, or Issues: read and write for issue create, issue comment, issue label and issue close; GitHub adds Metadata: read itself. Never Contents, Administration or Workflows: branches are pushed with git’s own credentials, and no verb merges on GitHub (arthur github pr --help), so even a leaked token pushes no code past arthur merge. Avoid a classic token: its repo scope reads and writes the code, issues and settings of every repository the account reaches, far beyond what the plugin needs, so a leaked one could push to any of them past arthur merge. Arthur does not check the token’s scope. Its value never goes into an error, a notice, an event or a file.
  • apiUrl: the REST API’s address; default https://api.github.com. GitHub Enterprise Server’s is https://<host>/api/v3.
  • poll.everySeconds: a whole number of seconds, 1 or more, between two polls; default 120. A poll asks once per project with a github.project({ workflow }), and GitHub allows a token 5000 requests an hour.
  • wakeOn: the events that wake the coordinator, each at most once, among ci-finished and pull-request-review; default ["ci-finished"], and [] wakes it on nothing. pull-request-review also turns on the polling of pull request reviews, which costs a request per project and one per pull request updated since the poll before.

Refused at load, with the option’s path: an unknown option or key, no instances, a name that is not a lowercase owner, two unnamed instances or one name twice, an apiUrl that is not https, or http on loopback (localhost, 127.0.0.0/8, ::1, where a test’s fake answers; anywhere else the token would cross the network in plain text), a poll.everySeconds below 1 or not whole, a wakeOn that is no list, names another event, or names one twice. At setup, naming the option or the project:

  • a token that is empty or that a header cannot carry: instances[<n>].tokenEnv: <variable> is empty or holds a space or a character outside ASCII, which a header cannot carry;
  • a project with a github.project({ workflow }) whose checkout has no origin: project <name>: github.project({ workflow }) is set, but its checkout has no origin remote to name its GitHub repository; one whose origin ends in no <owner>/<repository>: project <name>: its origin remote names no <owner>/<repository> (the remote’s URL is never said: it may hold a credential);
  • a project whose owner no instance is named after, with no unnamed instance: project <name>: no instance of github is named <owner>, the owner of <owner>/<repository>, and none is unnamed; github's instances: <names>.

A project without github.project({ workflow }) is not polled, and nothing of it is checked at load: arthur github finds its repository and instance when it runs for it, and refuses then, in the words above without github.project({ workflow }) is set, but . A piece of another shape is refused at load, before the setup: plugin github: setup failed: project <name>: github.project(...): expected { workflow }, a non-empty string: the workflow's file name or name.

arthur github pr list [--all] and arthur github pr get <n> read a project’s pull requests, pr get with its comments and reviews; pr create <branch> <file> [--base <branch>], pr comment <n> <file> and pr close <n> write them (arthur github pr --help); arthur github issue list [--all] and issue get <n> read its issues, issue create <file>, issue comment <n> <file>, issue label <n> <label> and issue close <n> write them (arthur github issue --help). The reads run inside a job too. Text people wrote on GitHub (titles, bodies, comments, reviews, label names) and arthur ci’s job names, step names and log lines are printed only after > , control characters dropped, so none reads as Arthur’s or the owner’s; the coordinator’s role takes them as data. A write is refused inside a job before any request, and pr merge always: a merge is arthur merge <job>, and the push of main marks the pull request merged. The token needs Pull requests: read for the pull request reads, read and write for their writes, and Issues: read and Issues: read and write likewise for the issues.

A project’s repository is its checkout’s origin, git@github.com:<owner>/<repository>.git or https://github.com/<owner>/<repository>; its workflow is the workflow of its piece, github.project({ workflow }) in its project file, the file name in .github/workflows/ (ci.yml) or the workflow’s id. At the start of arthur run, then every poll.everySeconds, each such project’s 100 newest runs of that workflow are asked for (GET /repos/<owner>/<repository>/actions/workflows/<workflow>/runs), one project after the other.

The branches in play are the checkout’s own branch (main) and the branch of every job of the project (host.jobs.list()), in any state, while it still exists in the checkout. A branch’s run is the newest run on the nearest commit of its first-parent line, from its tip back at most 1000 commits, that has one: a commit that touches no path the workflow watches has no run, so the run before it counts. Only a run whose event is push, whose head_branch is the branch and whose head_repository is the project’s repository counts: a pull request’s (a fork’s among them), a workflow_dispatch’s, a schedule’s, or another branch’s run on the same commit is ignored. A job’s branch not pushed yet has no run, as its commits from main ran as main.

Once a branch’s run is completed, and that attempt of it was not told before, the plugin emits ci-finished:

{ project, repo, workflow, run, attempt, sha, branch, branches, conclusion, url }

with run the run’s id and attempt its run_attempt, sha and branch the commit and the branch GitHub ran it on, branches the branches in play whose run it is (branch alone: only a run of the branch itself counts, so a job’s branch fresh from main has none), conclusion GitHub’s (success, failure, cancelled, timed_out, skipped, …) and url the run’s page. A run attempt is told once, however many polls see it. A rerun keeps the run’s id and raises its attempt, so its end is told again, once (AR0238). A branch deleted while in play leaves it at the next poll: its run is not told and nothing is said.

With ci-finished in wakeOn, each one that did not end success also reaches the coordinator as a coordinator-message, which it gets marked [Arthur: github]: CI run <id>, attempt <n>, of <workflow> in <project> ended <conclusion> on <branches> (<commit>): <url>, and for a run that failed or was cancelled a second line, Why: arthur ci <branch> --project <project>; then what to do for each case, as arthur ci --help says: for a job’s branch, a failure in the branch's own code goes back to its worker: arthur continue <job> '<the failed step and its lines>'; for main, or any branch no job has (host.jobs.list()), … goes to the owner: <branch> has no worker; then one that looks transient (a network error, a runner lost, a timeout in a step that passed before) is rerun once: arthur ci <branch> --project <project> --rerun. <branch> is the first branch the wake names. Before it, each branch is offered to collect("delivery.ciEnded", { project, branch, below, run }), below the commits from the branch’s tip to the run’s and run as GitHub listed it, whatever wakeOn says: a branch the delivery plugin answers true for, one that arthur merge --auto left waiting for this run, got delivery’s wake (arthur merge --help, “–auto”) and is left out of github’s, which is not sent when no branch is left (AR0257: one wake per run end). ci-finished still names every branch. A passed run wakes no one: it is told as ci-finished only.

The second line’s words are the procedure packages/github/roles/coordinator/ci-failed-worker.md for a job’s branch, ci-failed-owner.md beside it for any other, read as the wake is written, {branch}, {project} and {job} filled in.

Each coordinator-message the plugin sends, a run’s here and a review’s below, names its project (project), so a project with its own agent gets it in that agent’s inbox instead of the coordinator’s (arthur coordinator --help, “Project agents”).

With pull-request-review in wakeOn, each poll also asks, per project with a github.project({ workflow }), for its repository’s 100 open pull requests most recently updated, and for the reviews of each one that is new or whose updated_at changed since the poll before (submitting a review updates it). Each submitted review not told before (a pending one is a draft, not submitted) is emitted as pull-request-review:

{ project, repo, pull, title, branch, review, user, state, body, url }

with pull the pull request’s number, branch its head branch, review the review’s id, state GitHub’s (APPROVED, CHANGES_REQUESTED, COMMENTED, DISMISSED) and url the review’s page; and the coordinator gets, marked [Arthur: github], <user> reviewed pull request #<n> of <repo>, <title> (branch <branch>): <state>: <url>, then the review’s text, its first 1000 characters, when it has one; each line of it is quoted, so none reads as the owner’s (arthur coordinator --help). A project’s first poll of them tells none: what was reviewed before is taken as told. A pull request the poll before did not list (new, closed and reopened, or back among the 100) has told only its reviews whose submitted_at is at or after the second that poll began, so a reopened one does not tell its reviews again; one without a submitted_at is told. When a poll began is on GitHub’s clock, as submitted_at is: the date header of its answer to the list, less the time that answer took, so this machine’s clock running ahead or behind loses no review; this machine’s clock only when GitHub’s answer has no date.

The plugin provides github.push, { project, branch }, which delivery asks after a review’s PASS (the reviewed branch, arthur review --help), after arthur review-needed answers no review (the branch it waved through, arthur review-needed --help) and after arthur merge went in (main, arthur merge --help); with github not loaded, nothing is pushed. It runs git push --porcelain origin refs/heads/<branch>:refs/heads/<branch> in the project’s checkout, with git’s own credentials (an SSH key, a credential helper), and answers one line: github: pushed <branch> to origin: <old>..<new> ([new branch], [up to date]), or one warning line, github: <branch> not pushed to origin: <why>. <why> is git’s for a rejected push, [rejected] (non-fast-forward) or [rejected] (fetch first), origin left as it was; <folder> has no origin remote; or git’s first error line, a quoted remote URL said as origin, as it may hold a credential. A push never asks for anything: git’s terminal prompt is off (GIT_TERMINAL_PROMPT=0), no askpass program is run (GIT_ASKPASS empty, which also keeps git from core.askPass and SSH_ASKPASS; SSH_ASKPASS_REQUIRE=never for ssh), Git Credential Manager is told never to ask, and the push runs in a session of its own, with no terminal; one that has not ended in 60 s is killed, <why> no end in 60 s. No hook of the checkout’s config runs, so Git LFS’s pre-push hook does not either: a branch whose .gitattributes, at its tip and in any folder, names filter=lfs first gets git lfs push origin refs/heads/<branch>, the same way, and the branch is pushed only once that succeeded. git-lfs reads no protocol.<name>.allow: it writes into a folder origin and runs ssh to host <name> for a <name>:// one, so the upload runs only once git push --dry-run of the same branch passed, which refuses the transports the push refuses (docs/deploy.md, “Threat model”), <why> being the dry run’s (AR0399). The upload of large files may take longer than 60 s, so it has no fixed limit: it runs with GIT_LFS_FORCE_PROGRESS=1, which makes git-lfs print its progress to Arthur’s pipe too, and is killed only after 60 s without a byte of it (AR0391). <why> is then its .gitattributes names filter=lfs, and git-lfs is not installed (git-lfs must be on PATH; git would otherwise run a lfs alias of the config), its LFS objects were not pushed: no progress in 60 s, or its LFS objects were not pushed: <what git-lfs said>, its error line rather than the progress line before it, origin left as it was. A push that would need a password fails instead: fatal: could not read Username for origin: terminal prompts disabled. Nothing is retried; the next PASS, no review or merge pushes again.

A checkout whose own Git config (.git/config, the main checkout’s config.worktree, a file either includes) sets a key that may name a program, such as core.sshCommand, a credential helper, remote.origin.receivepack, an alias or an include, is pushed nothing and nothing is run: github: <branch> not pushed to origin: <file> sets <key>, which a job can write and which may name a program Arthur's git would run; remove it, or set it in your ~/.gitconfig. The allowed keys: docs/deploy.md, “Threat model”.

AR0555: a job’s branch leaves origin with its job. The plugin provides jobs.keep, which the core asks once arthur prune (or a merge’s or a dropped ticket’s prune, arthur merge --help) has freed a job’s worktree and its local branch, git branch -d having found it merged, or found it gone. It never answers a reason, so it never keeps a record; in the background, one job after the other, it deletes the job’s branch on origin with git push --porcelain --force-with-lease=<ref>:<tip> origin :<ref>, asking git ls-remote --symref origin HEAD <ref> for <tip> first, with the same no-prompt env, no hook and no program of the checkout’s config as a push. A branch is deleted only when:

  • it is named arthur/<job id> of that job: main, or any other name, is refused;
  • the project’s checkout does not have it checked out;
  • origin’s tip is the commit github.push pushed of it, recorded at the push in .arthur/github/pushed/<job id>, or one the checkout’s main holds (git merge-base --is-ancestor <tip> HEAD). So a dropped ticket’s branch, which git branch -D freed (packages/delivery/docs/delivery.md), goes from origin too, while a commit pushed there by anyone else keeps it.

The lease refuses a tip that moved between the look and the delete. A project without origin, and a branch origin does not have (never pushed, or deleted before: a prune of the same job again), is nothing to do and says nothing. A deletion is one line in the log, github: deleted <branch> on origin (<commit>), and takes the push record with it. A refusal a try again cannot change is one notice, github: <branch> not deleted on origin: <why>, <why> being it is not arthur/<id>, the branch of job <id>, <folder> has it checked out, origin's tip <commit> is not the commit Arthur pushed (<commit>|none recorded), nor in <main>, no project <name>, a key of the checkout’s config, or a refusal git’s porcelain prints for the ref, as for a push ([rejected] (stale info), the lease; [remote rejected] (pre-receive hook declined)); it never keeps the worktree, the local branch or the record, which are gone already. The push record stays.

AR0619: a failure of git’s own (origin out of reach, fatal: Could not read from remote repository., no end in 60 s, or a [remote rejected] whose reason is a server’s error, GitHub’s 5xx) is tried again. The plugin records the job’s project and branch, the tip it would delete (origin’s, or the one github.push recorded when origin could not be listed) and since when in .arthur/github/pending/<job id>, written to a temporary name and renamed, and says it once: github: <branch> not deleted on origin, retrying: <why>. Each poll (poll.everySeconds) first queues every recorded delete behind the prunes, unless the ones of the poll before are still on their way, with the same checks and lease as the first try; a second prune of the same job while it is recorded keeps the one record and its start. A retry that fails again says nothing; one that deletes it logs github: deleted <branch> on origin (<commit>) and takes the record; one refused for good is the refusal’s notice above and takes the record too. After 24 hours of failures the last one is told, github: <branch> still on origin after 24 h: <why>; arthur github branch sweep deletes it once origin answers, and the record goes. A record that is not what the plugin writes (broken, edited by hand) is none. arthur github branch sweep (arthur github branch --help) deletes a branch left so once main holds its tip, and the branches jobs left on origin before AR0555.

AR0560: arthur github branch list lists every branch on origin, with its tip, whether the checkout’s main holds it and the job on it, and arthur github branch delete <branch> [--unmerged] deletes any one branch there on the owner’s word, with the same lease, env and config check, never the checkout’s own branch, origin’s default branch or the branch of a job that has not ended (arthur github branch --help).

Roadmap entry 59. The plugin provides github.ci and github.cancel, which delivery’s arthur merge --auto and its CI waits ask through call (arthur merge --help, “–auto”); with github not loaded, --auto is refused, and only the owner’s recorded decision merges without CI (--no-ci --decision <id>, never with --auto). A plain arthur merge asks github.ci too and is refused only by a run on the branch’s own commits that ended other than success (AR0362). github.ci, { project, branch }, asks GitHub for the workflow’s 100 newest runs as arthur ci does and answers the run that built the branch, { id, attempt, sha, branch, status, conclusion, url, startedAt, below } (startedAt the attempt’s run_started_at, else created_at; below the commits from the branch’s tip to the one it ran on), or nothing when none did; a project without ci.workflow, a branch not in its checkout, and each refusal of GitHub’s reject with the line arthur ci prints for it. github.cancel, { project, run }, asks GitHub to cancel the run (POST /repos/<owner>/<repository>/actions/runs/<id>/cancel, which needs Actions: read and write) and answers github: cancel of run <id> of <owner>/<repository> asked; GitHub’s refusal, a 409 for a run already finished included, rejects.

.arthur/github/state.json holds, for each project, the run attempts already told that GitHub still lists, each <run id>/<run_attempt>, and, when pull request reviews are polled, when the last poll of them began and each open pull request’s updated_at and the reviews told; written to a temporary name and renamed when they change. A run that finished while arthur run was down is told at the first poll after it; one told before is not; likewise a review. A project’s first poll, with nothing in the file for it, tells nothing: what finished before Arthur watched it is taken as told. A file that is not what the plugin writes (broken, edited by hand, or entry 57’s list of run ids) is taken as no project polled yet, so nothing is told twice; so are a project’s pull requests written before AR0250, without the time of their poll. .arthur/github/reruns holds the ids of the runs arthur ci --rerun reran, one a line, and .arthur/github/pushed/<job id> the commit github.push last pushed of that job’s branch (above, “Branches on origin”).

  • A refusal the owner must fix is said once, as a notice, github: instance <name>: <reason>; polling goes on and says this again only after GitHub answered: 401: the token in <variable> was refused: <GitHub's message>, 403 for workflow <workflow> of <owner>/<repository>: <GitHub's message>; the token in <variable> needs Actions: read on it, 404: workflow <workflow> of <owner>/<repository> not found, or the token in <variable> cannot see it; for pull requests, 403 for the pull requests of <owner>/<repository>: ...; the token in <variable> needs Pull requests: read on it, said apart from the runs’ own. A 401 of an instance with several projects is one notice; it is said again once each of them was answered and is refused anew.
  • GitHub out of reach, no answer in 30 s, any other status, or an answer that holds no runs (no list of pull requests): one line on stderr, github: instance <name>: <reason>, likewise once until an answer. A failed request for pull requests or reviews leaves the poll’s state of them as it was, so the next poll asks again and nothing is lost.
  • A rate limit, as GitHub’s “Rate limits for the REST API” says: a refusal with retry-after (a 403 or 429) waits that many seconds; with x-ratelimit-remaining: 0, until x-ratelimit-reset; a 429, or a 403 that names a rate limit, without either, one minute. Until then the instance asks nothing, its other projects included, and one line goes to stderr: github: instance <name>: <status>, rate limited: <GitHub's message>; no request until <ISO time>. An answer with runs that says 0 requests left is used, and the instance waits for x-ratelimit-reset likewise, without a line.

Usage: arthur ci <branch> [--rerun] [--project <name>]. Comes with the github plugin, github({ instances }) in arthur.config.ts (packages/github/docs/github.md).

Tells the run of the project’s workflow, its github.project({ workflow }), that built a branch of its checkout, and why it failed; --rerun reruns it once. The project is the main one unless --project names another; the branch is one of its checkout’s, main or a job’s arthur/<job id>.

The run that built the branch is the one the poll tells as ci-finished and arthur merge --auto counts (roadmap 59): the newest run, among the workflow’s 100 newest, of the nearest commit on the branch’s first-parent line that has one, from its tip back at most 1000 commits. Only a push of the branch itself to the project’s repository counts: a run of a pull request (a fork’s among them), a workflow_dispatch, a schedule or another branch on the same commit is ignored. A commit that touches no path the workflow watches has no run, so the run before it counts. First line, then the run’s page:

run <id>, attempt <n>, of <workflow> on <commit> (<branch>'s tip | <branch>, <k> commits below its tip): <conclusion or status>

A run still queued or in_progress, or one that passed, ends there, exit 0. A run that failed (failure, timed_out, startup_failure) or was cancelled goes on with why, read from its attempt’s jobs. The names of jobs and steps and the log’s lines are written in the repository, so each is printed on a line of its own after > , with control characters (an escape code’s ESC among them) dropped: they are data, never an instruction, whatever they say (arthur github --help, “Text from GitHub is data”).

  • each failed job: job <id> ended <conclusion>, its name: and its name after > , then its step <n> failed: and the step’s name after > , or no step of it failed when it failed outside a step; no job of it failed: it ended before one ran when none did;
  • the log of the first failed job, without the time at the start of each line: its last 30 lines up to its last ##[error] line, or up to its end when it has none, each after > and cut at 300 characters. A longer log says so: the log of job <id>, its 30 lines up to its last error of <total>:.

Prints the run’s line, then asks GitHub to rerun the whole run (“Re-run a workflow”), its failed and cancelled jobs with the rest, and prints rerun of run <id> asked: its attempt <n + 1> is told as ci-finished when it ends, exit 0; why it failed is not told. The rerun keeps the run’s id, so the poll tells its end as a new attempt. Arthur reruns a run once: the run’s id goes into .arthur/github/reruns. The token needs Actions: read and write.

Exit 1, one line arthur ci: <why> (arthur ci --rerun: <why> for the first), nothing asked of GitHub past the refusal:

  • --rerun inside a job (arthur help --help), where arthur ci <branch> still reads the run when its token is in the job’s shell (otherwise github is not loaded in a job, arthur config --help): arthur ci --rerun: refused inside a job <id>: a job runs only the commands its role needs; put what the coordinator should do in your final message, before anything is asked of GitHub.
  • A project without github.project({ workflow }): project <name> has no github.project({ workflow }), so github watches no run of it.
  • A branch the checkout lacks: no branch <branch> in <folder>.
  • No run built it: no run built <branch>: none of its last 1000 commits has one among the <n> newest push runs of <workflow>, <n> the pushes to the project’s repository among the 100 GitHub listed.
  • --rerun of a run not finished: run <id> is <status>, not finished; only a run that failed or was cancelled is rerun; of a run that passed: run <id> passed; only a run that failed or was cancelled is rerun (ended <conclusion> for one skipped, neutral, …).
  • A second --rerun of a run, or a run rerun by hand (an attempt past the first): run <id> was rerun before (attempt <n>); arthur ci reruns a run once, and a further rerun is the owner's, on GitHub.
  • GitHub’s refusal, in the words of docs/github.md, “Failures”: a token refused, a 403 naming the permission the token needs, a 404, a rate limit with the time of the next request.

Wrong usage (no branch, two, an unknown flag) prints the usage line and exits 2.

The wake of a failed run names what to do for each case. Run arthur ci <branch> first: a failure in the branch’s own code goes back to its worker (arthur continue <job> '<the failed step and its lines>'), or to the owner on main or a branch no job has, which has no worker; one that looks transient (a network error, a runner lost, a timeout in a step that passed before) is what --rerun is for, once. A rerun that fails again goes to the owner.

Usage: arthur github branch list; arthur github branch delete <branch> [--unmerged]; arthur github branch sweep [--dry-run]; each with [--project <name>]. The shared rules (the project, the refusals inside a job) are arthur github --help.

The branches of the project’s repository on origin, reached with git’s own credentials, as github.push pushes them (packages/github/docs/github.md, “Pushes”): the token is never used, so it needs no permission for them.

Every branch on origin, read with git ls-remote --symref origin HEAD 'refs/heads/*', one line each in origin’s order: <branch> <commit> <where>, <where> being merged into <main> (the checkout’s main holds the tip), not in <main>, or not here (the checkout does not have the commit), then , job <id> (<state>) when a job’s record names that branch, the newest one. With none: no branches on origin of project <name>. It is a read, so it runs inside a job too. Exit 0.

Deletes one branch on origin with git push --porcelain --force-with-lease=refs/heads/<branch>:<tip> origin :refs/heads/<branch>, <tip> the one git ls-remote --symref origin HEAD refs/heads/<branch> just listed, and prints deleted <branch> on origin (<commit>), exit 0. Like a push, it never asks for a password and runs no hook of the checkout’s, nor a program its config or origin’s URL names. Refused, exit 1, nothing deleted, with arthur github: <branch> not deleted on origin: <why>, <why> being:

  • <folder> has it checked out: the checkout’s own branch, main;
  • it is the branch of job <id>, which has not ended (<state>): arthur jobs shows it; once it ended, the delete goes on;
  • it is origin's default branch: the one origin’s HEAD names;
  • origin has no such branch: never pushed, or deleted already, so a second delete is refused;
  • its tip <commit> is not in <main>; --unmerged deletes it all the same: the checkout’s main does not hold the tip, or does not have it; --unmerged, on the owner’s word only, deletes it anyway;
  • origin’s refusal of the push, such as [rejected] (stale info): the lease, when the tip moved since the listing, or [remote rejected] (<why>), or git’s first error line.

An origin it may not reach is refused as “Refused” below says. It is a write, so a job’s call is refused before any of it.

Deletes origin’s arthur/* branches that nothing needs any more, the ones jobs left before Arthur deleted a pruned job’s branch itself (packages/github/docs/github.md, “Branches on origin”). It lists them with git ls-remote --symref origin HEAD 'refs/heads/arthur/*', and deletes, in one git push --porcelain origin --force-with-lease=<ref>:<tip>... :<ref>..., each one that is:

  • named arthur/<job id>, <date>-<kind>-<8 hex digits> as a spawn names a job’s branch;
  • of a job that is gone: no record in arthur jobs;
  • at a tip the checkout’s main holds (git merge-base --is-ancestor <tip> HEAD); a tip the checkout does not have is not held.

Every other one is kept. The lease deletes a branch only while origin still has the tip it listed, so a commit pushed in between keeps it. Like a push, it never asks for a password and runs no hook of the checkout’s, nor a program its config or origin’s URL names. A branch’s push record (.arthur/github/pushed/<job id>) goes with it.

Each branch is one line, in origin’s order, then a count:

  • deleted <branch> (<commit>);
  • kept <branch>: <why>, <why> being not arthur/<job id>, its job still exists; arthur prune <id> frees it, its tip <commit> is not in <main>, or origin’s refusal of the delete, such as [rejected] (stale info) (the lease) or [remote rejected] (<why>);
  • <n> deleted, <m> kept, or with none on origin no arthur/* branches on origin of project <name>.

--dry-run deletes nothing: would delete <branch> (<commit>) for each one it would delete, then --dry-run: <n> would be deleted, <m> kept; nothing deleted. Run it first, and the sweep itself once the owner has read the list.

Exit 0, or 1 when origin refused a delete: run the sweep again for the branches it kept that way.

As arthur github --help says, and exit 1, nothing deleted, for an origin any verb may not reach: origin's branches of project <name> not listed: <why>, <why> being <folder> has no origin remote, the checkout’s own config setting a key that may name a program (<file> sets <key>, which a job can write and which may name a program Arthur's git would run; remove it, or set it in your ~/.gitconfig), or git’s first error line (origin’s URL, which may hold a credential, said as origin). branch sweep and branch delete are writes, so a job’s call is refused before any of it; branch list runs in a job.

Usage: arthur github issue list [--all]; arthur github issue get <n>; arthur github issue create <file>; arthur github issue comment <n> <file>; arthur github issue label <n> <label>; arthur github issue close <n>; each with [--project <name>]. The shared rules (the project, the > marking, the refusals) are arthur github --help.

The token needs Issues: read on the repository to read, and Issues: read and write for issue create, issue comment, issue label and issue close.

GitHub numbers issues and pull requests alike, and its issues API serves both: issue list drops the pull requests, and issue get, issue comment, issue label and issue close refuse a pull request’s number, nothing written (arthur github pr --help reads and writes pull requests).

  • issue list [--all]: the open issues of the project’s repository, every one with --all, most recently updated first. Each is one line, #<n> <state>, by <login>, updated <day>, <state> open or closed, and for a closed one GitHub’s reason after , (completed, not_planned) when it gives one, then its title after > . With none: no open issues in <owner>/<repository> (no issues in … with --all).

  • issue get <n>: one issue:

    • issue #<n> of <owner>/<repository>: <state>;
    • by <login>; created <day>, updated <day>, then , closed <day> when it was;
    • its page;
    • title: and the title after > ; labels: and each label’s name after > , or labels: none; body: and each line of the body after > , or body: none;
    • its comments, oldest first, each comment <id> by <login> on <day> and its text after > , or no comments.

    A pull request’s number: #<n> is a pull request: arthur github pr get <n>, exit 1.

A list is read page by page, 100 items a page, pull requests counted, until a page holds fewer, at most 10 pages: a list cut there ends with the issues stop at 10 pages of 100: GitHub may hold more (the comments …). Days are GitHub’s, in UTC.

Each write is refused inside a job before any request (arthur github --help); the coordinator writes only on the owner’s word.

  • issue create <file>: the file’s first line, a Markdown heading’s # dropped, is the title; the rest, trimmed, the body (as pr create and youtrack issue create). Sends POST /repos/<owner>/<repository>/issues with title and body, and prints created issue #<n>: <page>. Refused before any request: cannot read <file>: <code>, <file> is empty, <file> starts with an empty heading; its first line is the title, the rest the body, each ending ; nothing was asked of GitHub.
  • issue comment <n> <file>: reads the issue, then adds the whole file, trimmed, as a comment (POST /repos/<owner>/<repository>/issues/<n>/comments with body), and prints comment <id> added to issue #<n> of <owner>/<repository>: <page>. Refused before any request: a file it cannot read or an empty one, as for issue create. A pull request’s number: #<n> is a pull request: arthur github pr comment <n> <file>; nothing was written.
  • issue label <n> <label>: reads the issue, then the repository’s labels (GET /repos/<owner>/<repository>/labels), and adds the one named <label> in any case, under the repository’s own name for it (POST /repos/<owner>/<repository>/issues/<n>/labels with labels); prints label added to issue #<n> of <owner>/<repository>: and the name after > . GitHub would make a label the repository lacks, so a typo is refused instead: <owner>/<repository> has no label <label>, in any case; nothing was written. Refused too: issue #<n> of <owner>/<repository> has the label <label> already; nothing was written, and a pull request’s number, #<n> is a pull request: arthur github labels issues only; nothing was written.
  • issue close <n>: reads the issue, then closes it as completed (PATCH /repos/<owner>/<repository>/issues/<n> with state: closed and state_reason: completed), and prints closed issue #<n> of <owner>/<repository> as completed. Refused: one closed already, issue #<n> of <owner>/<repository> is closed already; nothing was written, and a pull request’s number, #<n> is a pull request: arthur github pr close <n>; nothing was written.

A write that got no answer in 30 s may still have been made on GitHub: read it with issue list or issue get before you write it again; nothing retries on its own.

As arthur github --help says; a number no issue or pull request has is GitHub’s 404: issue #<n> of <owner>/<repository> not found, or the token in <variable> cannot see it.

Usage: arthur github pr list [--all]; arthur github pr get <n>; arthur github pr create <branch> <file> [--base <branch>]; arthur github pr comment <n> <file>; arthur github pr close <n>; arthur github pr merge <n>; each with [--project <name>]. The shared rules (the project, the > marking, the refusals) are arthur github --help.

The token needs Pull requests: read on the repository to read, and Pull requests: read and write for pr create, pr comment and pr close.

  • pr list [--all]: the open pull requests of the project’s repository, every one with --all, most recently updated first. Each is one line, #<n> <state>, <head> -> <base>, by <login>, updated <day>, <state> open, closed or merged and , draft after a draft, then its title after > . With none: no open pull requests in <owner>/<repository> (no pull requests in … with --all).
  • pr get <n>: one pull request:
    • pull request #<n> of <owner>/<repository>: <state>;
    • <head> -> <base>, by <login>; created <day>, updated <day>, then , closed <day> and , merged <day> when it was;
    • its page;
    • title: and the title after > ; body: and each line of the body after > , or body: none;
    • its comments, oldest first, each comment <id> by <login> on <day> and its text after > , or no comments;
    • its reviews, oldest first, each review <id> by <login>: <STATE> on <day> (APPROVED, CHANGES_REQUESTED, COMMENTED, DISMISSED) and its text after > when it has one, or no reviews. A pending review, a draft its author has not submitted, is left out.

A list is read page by page, 100 items a page, until a page holds fewer, at most 10 pages: a list cut there ends with the pull requests stop at 10 pages of 100: GitHub may hold more (the comments …, the reviews …). Days are GitHub’s, in UTC.

Each write is refused inside a job before any request (arthur github --help); the coordinator writes only on the owner’s word.

  • pr create <branch> <file> [--base <branch>]: asks to merge <branch>, already on GitHub, into --base, else the branch the project’s checkout is on. The file’s first line, a Markdown heading’s # dropped, is the title; the rest, trimmed, the body (as youtrack issue create). Sends POST /repos/<owner>/<repository>/pulls with title, head, base and body, and prints created pull request #<n>: <page>. Refused before any request: cannot read <file>: <code>, <file> is empty, <file> starts with an empty heading; its first line is the title, the rest the body, <branch> is the base too: a pull request asks to merge a branch into another, and the checkout of project <name> is on no branch to be the base; give --base <branch>, each ending ; nothing was asked of GitHub. GitHub’s 422 is said with each of its errors: 422 for a pull request of <branch> into <base> in <owner>/<repository>: Validation Failed: <error>, such as No commits between main and <branch>, PullRequest head invalid (no such branch on GitHub), or A pull request already exists for <owner>:<branch>..
  • pr comment <n> <file>: reads the pull request, then adds the whole file, trimmed, as a comment (POST /repos/<owner>/<repository>/issues/<n>/comments with body), and prints comment <id> added to pull request #<n> of <owner>/<repository>: <page>. Refused before any request: a file it cannot read or an empty one, as for pr create. A number no pull request has is GitHub’s 404, then ; it may be an issue: arthur github issue comment <n>, and nothing is written.
  • pr close <n>: reads the pull request, then closes it (PATCH /repos/<owner>/<repository>/pulls/<n> with state: closed), a draft too, and prints closed pull request #<n> of <owner>/<repository>; its branch <head> stays on origin. Refused: one closed or merged already, pull request #<n> of <owner>/<repository> is closed already; nothing was written (is merged already).

A write that got no answer in 30 s may still have been made on GitHub: read it with pr list or pr get before you write it again; nothing retries on its own.

pr merge <n> only refuses, asking GitHub nothing: a merge is arthur merge <job> --decision <id>; main's push marks the pull request merged; nothing was asked of GitHub, exit 1. A merge on GitHub would put a commit on origin’s main that no arthur merge review or CI check covered; it would need Contents: write on the token; and it would leave the checkout’s main behind origin, so the next push of main would be rejected. Inside a job it is refused as every write is (arthur github --help).

As arthur github --help says; pr get of a number that is no pull request, an issue’s included, is GitHub’s 404: pull request #<n> of <owner>/<repository> not found, or the token in <variable> cannot see it.

Usage: arthur github pr list [--all]; arthur github pr get <n>; arthur github pr create <branch> <file> [--base <branch>]; arthur github pr comment <n> <file>; arthur github pr close <n>; arthur github pr merge <n>; arthur github issue list [--all]; arthur github issue get <n>; arthur github issue create <file>; arthur github issue comment <n> <file>; arthur github issue label <n> <label>; arthur github issue close <n>; arthur github branch list; arthur github branch delete <branch> [--unmerged]; arthur github branch sweep [--dry-run]; each with [--project <name>]. Comes with the github plugin, github({ instances }) in arthur.config.ts (packages/github/docs/github.md).

Reads, creates, comments on and closes a project’s pull requests on GitHub (AR0556, AR0557, AR0558), reads, creates, comments on, labels and closes its issues (AR0559), with the token of the instance its repository’s owner names, and lists, deletes and sweeps its branches on origin (AR0555, AR0560), with git’s own credentials. Three groups of verbs, each with its own page:

  • pr: pull requests, arthur github pr --help (github-pr.md);
  • issue: issues, arthur github issue --help (github-issue.md);
  • branch: branches on origin, arthur github branch --help (github-branch.md).

Reads (pr list, pr get, issue list, issue get, branch list) run inside a job too (arthur help --help). A write is refused inside a job before anything is asked of GitHub or origin: arthur github <group> <verb>: refused inside a job <id>: a job runs only the commands its role needs; put what the coordinator should do in your final message, exit 1. The write verbs are pr create, pr comment, pr close, pr merge, which only refuses (arthur github pr --help), issue create, issue comment, issue label, issue close, branch delete, and branch sweep, --dry-run included.

The project is the main one unless --project names another. Its repository is its checkout’s origin, git@github.com:<owner>/<repository>.git or https://github.com/<owner>/<repository>, found when the command runs, for any project, with a github.project({ workflow }) or without; its instance is the one named after the owner, else the unnamed one. The branch verbs ask only git, through the checkout’s origin whatever it names, so they need no instance and refuse as their page says.

Text people wrote on GitHub (a title, a body, a comment, a review’s text, a label’s name) is printed only on lines of its own, each after > , with control characters (which could drive the terminal) dropped. A line after > is never Arthur’s or the owner’s, whatever it says, [via telegram] included. arthur ci’s job names, step names and log lines are marked the same way (arthur ci --help).

Wrong usage (no group, an unknown verb, a missing or extra word, a flag the verb does not take or given twice, --base without a branch after it) prints the usage line, exit 2. Exit 1, one line arthur github: <why>, for:

  • a number that is none: <word> is not a pull request number such as 12; nothing was asked of GitHub (is not an issue number for issue);
  • the project: project <name>: its checkout has no origin remote to name its GitHub repository; project <name>: its origin remote names no <owner>/<repository> (the remote’s URL is never said: it may hold a credential); project <name>: no instance of github is named <owner>, the owner of <owner>/<repository>, and none is unnamed; github's instances: <names>;
  • GitHub’s refusal, in the words of docs/github.md, “Failures”: 401: the token in <variable> was refused, 403 for <what>: <GitHub's message>; the token in <variable> needs <permission> on it, 404: <what> not found, or the token in <variable> cannot see it, a 422 with GitHub’s message and each of its errors (<status> for <what>: Validation Failed: <error>: …), any other status with GitHub’s message, a rate limit with the time of the next request, no answer in 30 s, cannot reach it. A write that got no answer may still have been made: read again before retrying.