Revision: 1 Last modified: 2026-12-04T18:15:21Z
This is a library. It is sourced by scripts/forge/forge.sh, never executed. No shebang, mode
rw-rw-r--.
GitHub adapter — GitHub REST (api.github.com) over curl. It implements the same provider contract as
scripts/forge/providers/gitea.sh; read that guide for the contract itself. This guide records what is
specific to GitHub.
Three GitHub behaviours are handled here and are easy to get wrong:
- A renamed repository answers
301with aurlon the same API origin (/repositories/<id>).prov_repofollows that one hop itself (becauselib/http.shnever follows redirects) and continues with the canonicalfull_name, printingNOTE: repo_moved canonical=o/r. A redirect to any other origin is refused before a second request — that is the token pin. - A draft release is invisible to
GET /releases/tags/{tag}. On a404there, the first page of the release list (100 items) is searched for a draft of that tag, so a draft is reported (andrelease-ensurerefuses it aspresent_mismatch) instead of a second release being created. - A
422on create means "already exists" only when the body sayserrors[].code == "already_exists". Any other422(bad target, bad tag) is a real error.
FG_TARGET_DERIVED=0: GitHub's target_commitish is the stored request field — documented as "unused if the
Git tag already exists" — so a target read back is the value that was sent, never proof of where the tag
points. forge.sh therefore verifies the tag's own commit and treats a matching target as NOTE: target_echo_only.
As for every provider: sourced by forge.sh after lib/common.sh / lib/credentials.sh / lib/http.sh, with
FG_OWNER, FG_REPO, FG_API_BASE, FG_API_ORIGIN and an initialised FG_TMP. Needs jq.
Through forge.sh (this file is not invoked directly):
bash scripts/forge/forge.sh detect --remote origin
bash scripts/forge/forge.sh probe --remote origin
bash scripts/forge/forge.sh tag-get --remote origin --tag v1.2.3
# a draft release is found by the list fallback and refused as a mismatch
bash scripts/forge/forge.sh release-get --remote origin --tag v1.2.3Contract check in isolation:
bash -c '. scripts/forge/lib/common.sh; . scripts/forge/providers/github.sh; FG_OWNER=o FG_REPO=r; prov_init; \
printf "%s|%s|%s|%s\n" "$FG_AUTH_FMT" "$FG_RPATH" "$FG_PRE_SUPPORTED" "$FG_TARGET_DERIVED"'Library: functions return 0 when a state was determined and 1 only when no HTTP answer arrived
(FG_NET set). Every HTTP status is a result encoded in the state variables. User-visible exit codes belong to
forge.sh — see docs/scripts/forge.md.
- A
301to a foreign origin — refused withFG_NET=pin; no second request is made, so the token is never sent to the redirect target. - A
301whoseurldoes not match/repositories/<digits>on the pinned origin — alsoFG_NET=pin. - A
301that resolves but whosefull_namedoes not survive.-segment validation —FG_CODEis forced to000, so the caller sees an unusable status rather than a half-trusted name. - A
404on/releases/tags/{tag}— the list fallback runs. If the list itself is not200, the answer isNOTE: draft_lookup_unavailable (release list answered status=<code>)and the state staysabsentwithFG_CODE=404. If the list holds 100 items with no draft of the tag,NOTE: draft_lookup_first_page_only— a draft beyond the first page is not seen, stated rather than assumed away. - An annotated tag —
/git/ref/tags/{tag}reportsobject.type: tag, so a second GET/git/tags/{sha}peels it; the commit id is only used when the object type resolves tocommit. OtherwiseTAG: present sha=unknown. - A ref that does not actually point at the requested tag name — treated as
absent, so a stale or differently-named ref cannot be mistaken for the tag. - A
422withoutalready_exists— a real error;FG_CREATEstayserrorandforge.shreportsunexpected_status_422. - Write paths (
POST /releases,PATCH /releases/{id}) are LIVE-UNPROVEN.
prov_init—Authorization: Bearer %s, headersAccept: application/vnd.github+jsonandX-GitHub-Api-Version: 2022-11-28,FG_RPATH="/repos/$FG_OWNER/$FG_REPO",FG_PRE_SUPPORTED=1,FG_TARGET_DERIVED=0.prov_repoGETs the repository; on301it validates theurlagainst the pinned origin and the/repositories/<digits>shape, GETs it, and re-derives owner/repo fromfull_nameafter.-segment checks.prov_release_getGETs/releases/tags/{tag};200fills the release fields,404calls_github_draft_lookup._github_draft_lookupGETs/releases?per_page=100and usesjqto count entries with a matchingtag_nameanddraft == true; a hit is written to$FG_TMP/page.jsonand read back into the release fields withFG_REL_DRAFT=true._github_payloadbuilds{tag_name,target_commitish,name,body,draft:false,prerelease}withjq -n, reading the notes with--rawfile.prov_tag_getGETs/git/ref/tags/{tag}, requires.ref == refs/tags/<tag>, peels an annotated tag via/git/tags/{sha}, and setsFG_TAG_SHAonly when the final object type iscommit.prov_probeissues three read-only GETs: repo,/releases?per_page=1,/tags?per_page=1.
scripts/forge/providers/gitea.sh— the canonical provider-contract statement this file implements.scripts/forge/forge.sh— the driver (prov_init,prov_tag_get,prov_release_*).scripts/forge/lib/http.sh— the HTTP client; never follows redirects, hence the manual301hop here.scripts/release/tag_and_release.sh— keeps its ownghlegs by design decision; a separate path, not a duplicate.config/forge/hosts.tsv— mapsgithub.comtogithubwith token variablesGITHUB_TOKEN,GH_TOKEN.
2026-12-04 — bash -n scripts/forge/providers/github.sh → exit 0. Contract check a reader can repeat:
bash -c '. scripts/forge/lib/common.sh; . scripts/forge/providers/github.sh; FG_OWNER=o FG_REPO=r; prov_init; \
printf "%s|%s|%s|%s\n" "$FG_AUTH_FMT" "$FG_RPATH" "$FG_PRE_SUPPORTED" "$FG_TARGET_DERIVED"'Expected: Authorization: Bearer %s|/repos/o/r|1|0.