Revision: 1 Last modified: 2026-12-04T00:00:00Z
Library: scripts/pr/lib/provider.sh (sourced by scripts/pr/lib/preflight.sh and lib/steps.sh; never
executed on its own). Engine guide: docs/scripts/pr_deliver.md. Manual:
docs/manuals/pr_delivery_engine_manual.md.
Decide WHICH forge answers for the configured remote, WHICH credential may be used for it, and route every
provider read and write to one adapter. The adapter surface is deliberately small and provider-neutral, so
the state machine in lib/steps.sh never contains a provider name.
This file owns four things: resolving the provider from the remote URL, probing the credential, calling a
REST provider with the token OUT of argv and out of the child environment, and dispatching each verb to
prv_<provider>_<verb> (implemented in provider_github.sh and
provider_rest.sh).
config/forge/hosts.tsv— the existing host → provider → api_base → token_vars map, reused, never copied.git(the remote URL is the only place a provider is derived from),ghfor GitHub,curl+jqfor the REST providers.- Credentials supplied by name in the environment. The value is read at call time and never printed.
. "$PR_SELF_DIR/lib/provider.sh"
pr_provider_resolve || exit 3 # sets PR_PROVIDER PR_API_BASE PR_TOKEN_VARS PR_REMOTE_URL PR_REPO_SLUG
pr_cred_probe || exit 3 # sets PR_CRED_NAME PR_CRED_KIND (env|keyring); never a value
prv_identity # the authenticated account name
prv_repo_probe # archived=… default_branch=… allow_merge_commit=… push=… admin=…
prv_pr_list_head task/CON-641-x # number= state= head= base= draft= url=Which credential answered, without ever printing it:
$ bash scripts/pr/pr_deliver.sh preflight --task CON-641 | sed -n '/^CHECK P5/p'
CHECK P5 credential PASS identity=… via=env:GITHUB_TOKEN_PR_WRITEpr_remoteunset is tolerated only when the repository has exactly ONE remote; two or more isprovider_ambiguous:pr_remote_unset_and_<n>_remotes.- A remote with several push URLs is refused (
provider_ambiguous:pr_remote_<r>_has_<n>_push_urls). A fan-out remote would push a task branch to every mirror, widening retirement and publishing the branch where nobody expects it. This is why the declaration names a single-host remote. - A configured
pr_providerthat disagrees with the hosts map is a refusal, not a preference:provider_ambiguous:config_says_<a>_host_says_<b>. - An unknown host is never guessed at (
unknown_forge:<host>), and a provider with no adapter isprovider_unimplemented:<provider>. - Every credential candidate is tried, then the GitHub keyring last. A candidate that is unset is
recorded as
(unset), a candidate the provider refuses as(refused); the first line of the provider's own error text is kept and redacted, so a refusal can quote the platform instead of inventing a reason. - A missing
jqis a refusal, never a silent empty answer (pr_tool_absent:jqat preflight; the REST adapters print a diagnostic and return 1). - The token never appears in argv or in the child environment:
pr_rest_callwrites a0600curl config to$TMPDIR, passes it with--config, and removes it immediately after the call.
pr_host_of_url/pr_slug_of_urlderive the host andowner/repofrom either anhttps://or agit@host:pathURL;pr_hosts_rowlooks the host up in the TSV.pr_cred_probeprobes one cheap authenticated GET (repos/<slug>for GitHub,/projects/<urlencoded>for GitLab,/repos/<slug>for Gitea) and records the winner inPR_CRED_NAME/PR_CRED_KIND. On total failure it setsPR_CRED_TRIEDandPR_CRED_LAST_ERRfor the refusal text.pr_cred_describeis the honest one-line record:keyring-oauth,env:<NAME>ornone.pr_rest_call METHOD PATH [BODY_FILE]prints the body and returns 0 on 2xx, otherwise printsHTTP <code>and returns 1;PR_LAST_HTTPcarries the code. A missing token answersHTTP 401without a request.pr_adapter VERB …resolvesprv_<provider>_<verb>; a missing implementation printsREASON: provider_unimplemented:<provider>:<verb>and returns 3, so a partially implemented provider fails loudly instead of silently doing nothing.- Every call clears the caller's
GIT_*repository-locating variables (pr_gitinlib/common.sh), so an inherited environment can never redirect a delivery at a different repository.
provider_github.md— theghadapter (the only lifecycle measured on this host).provider_rest.md— the GitLab and Gitea REST adapters, and what is UNCONFIRMED there.preflight.md— consumes the resolve/probe results as checks P3–P5.common.md—pr_field,pr_redact,pr_git.forge_tool.md— the sibling tool that reads the sameconfig/forge/hosts.tsv.
2026-12-04 — read against scripts/pr/lib/provider.sh (345 lines). The config/forge/hosts.tsv reuse and
the single-push-URL refusal are the code's, not a policy wish.