Skip to content

Latest commit

 

History

History
88 lines (70 loc) · 5.14 KB

provider_github.md

File metadata and controls

88 lines (70 loc) · 5.14 KB

provider_github.sh — guide

Revision: 1 Last modified: 2026-12-04T00:00:00Z

Adapter: scripts/pr/lib/provider_github.sh (sourced by scripts/pr/lib/provider.sh; never executed on its own). Engine guide: docs/scripts/pr_deliver.md. Manual: docs/manuals/pr_delivery_engine_manual.md.

Overview

Implement the provider-neutral verb surface of lib/provider.sh over the gh CLI. GitHub is the one provider whose full lifecycle was MEASURED on this host: create a pull request, review it, merge it and delete the branch all answered successfully, while an author self-approval answers 422 by platform policy.

Every verb emits one line of key=value pairs separated by single spaces, so callers parse with sed/awk and never need a JSON parser. Bodies are reduced to their single-line PR-* marker, which is what makes a read-back verification possible in pure shell.

Prerequisites

  • gh on PATH (override: PR_GH_BIN), authenticated by a token variable or by the CLI keyring.
  • PR_REPO_SLUG, PR_CRED_NAME, PR_CRED_KIND set by lib/provider.sh. PR_API_BASE is unused: gh owns the endpoint and the authentication.
  • No jq is required — the --jq expressions below are evaluated by gh itself.

Usage examples

. "$PR_SELF_DIR/lib/provider.sh"      # this adapter is sourced at the end of provider.sh

prv_identity                     # the authenticated login
prv_repo_probe                   # archived= … allow_merge_commit= … push= … admin= …
prv_rules main                   # rule=pull_request approvals=0 contexts=
prv_pr_create task/CON-641-x main "CON-641: …" /tmp/body   # prints the new pull request number
prv_merge 128 4f2c1a9… merge-commit                        # pins the head

Edge cases

  • Every write prints the provider's OWN error text on failure and returns 1, in exactly ONE provider invocation. A refusal therefore quotes the platform instead of inventing a reason — the measured 422 "Review Can not approve your own pull request" reaches the operator verbatim.
  • A credential is selected before the call, never after. With PR_CRED_KIND=keyring the three ambient token variables are unset for the child (env -u GITHUB_TOKEN -u GH_TOKEN -u GITHUB_TOKEN_PR_WRITE); with an env credential only that one variable is set for the child. The ambient token the owning organisation answers 403 to can never shadow the keyring credential that works.
  • prv_rules reads /rules/branches/<base> first, because the classic /branches/<b>/protection endpoint answers 404 "Branch not protected" for a ruleset-protected branch — a false "no protection" that would have opened a pull request into an unmergeable state. The classic endpoint is the fallback for a server without the rules API, and rule=none approvals=0 contexts= is the answer when neither reports a rule.
  • prv_pr_create without a pull request URL is a failure, not an empty number: the engine must never proceed on a pull request whose number it could not read.
  • Only a merge commit is offered. gh pr merge has no fast-forward mode, and a squash or a rebase would lose the reviewed head; both are refused here rather than requested and silently accepted.
  • prv_merge pins the head with --match-head-commit, so a head that moved between the read-back and the merge is refused BY THE PLATFORM rather than by the engine's own timing.
  • prv_comments returns only PR-VERDICT/PR-GO marker lines, joined with ;; when a body carries more than one; the read-backs in lib/steps.sh parse exactly those.

Internal behaviour

  • _pr_gh_write captures stdout and stderr into two mktemp files, returns 0 leaving nothing behind, and on failure prints the first 400 characters of the provider's message with newlines flattened.
  • _pr_gh_api / _pr_gh_err (in lib/provider.sh) are the read and error-text halves, with the same credential selection.
  • Read verbs use --jq filters that emit the neutral record shape directly, so no JSON ever reaches the shell: prv_pr_view emits number= state= head= base= draft= mergeable= merge_state= merge_commit= url= head_owner=.
  • head_owner is what lets merge refuse a fork pull request with fork_pr_unsupported:<owner>; a provider that reports nothing makes the engine claim nothing.
  • prv_branch_delete deletes refs/heads/<branch> through the git-refs API; prv_assign and prv_request_reviewers build one --add-* flag per list member and are no-ops on an empty list.

Related scripts

  • provider.md — the verb contract, the credential probe and the dispatch.
  • provider_rest.md — the same surface over GitLab and Gitea REST.
  • steps.sh — the consumer of every verb and of every read-back.
  • forge_tool.md — the sibling Forge tool over the same gh CLI.

Last verified

2026-12-04 — read against scripts/pr/lib/provider_github.sh (172 lines). The 422 self-approval text and the ruleset-404 behaviour are recorded measurements of this host, not assumptions; they are exercised hermetically by tests/pr/test_pr_preflight.sh and tests/pr/test_pr_lifecycle.sh.