What changed: an audit of every request magpie makes to GitHub's API
after the git-plugin fix. The library's skill checks, private-repo probes
and RTK's release check already carried the token; the Plugins page's
git-plugin check and topic search got it in the previous commit. The one
left was Bun's newest-release check (bunLatest), asked of
api.github.com/repos/oven-sh/bun/releases/latest anonymously through
getURL. getURLFrom now has a request to GitHub's API's host carry the
token (ghtoken.Authorize), and bunLatest asks githubAPI so tests can
move it. Bun's zips (github.com, npmmirror) are other hosts and never
get it. With a token set, that one request isn't sent to the
MAGPIE_MIRRORS fallback (source.Do sends nothing with Authorization to a
mirror), the same as the library's API requests.
Left as they are: Copilot's api.github.com requests carry the user's
Copilot sign-in, not this token; raw.githubusercontent.com and codeload
aren't the rate-limited REST API; site/worker.js is the website's.
What was run:
- TestBunReleaseCheckCarriesGitHubToken (new): bunLatest is asked with
"Bearer github-env", a download from another host with none. With the
Authorize call removed it fails: "Bun's release was asked of GitHub's
API with Authorization """.
- go test -tags nogui -run 'Bun' ./internal/plugin: ok.
- gofmt -l clean; go vet -tags nogui darwin, GOOS=linux, GOOS=windows on
internal/plugin: clean.
What changed: a plugin installed from GitHub (github:owner/repo) is
checked by asking GitHub's API for its branch's commit (githubHead,
through fetchJSON). That request went without a token, so a token saved
in Settings → Network and sharing did nothing for it: the check stayed
at GitHub's 60 requests an hour for the whole address, which a shared
proxy exit uses up, and the row said only "<url>: 403 Forbidden".
- The token lookup, where a token may go and how a rate limit is told
move from internal/library into a new internal/ghtoken, shared by the
library and the plugin package (plugin can't import library).
The order is unchanged: Settings, then GITHUB_TOKEN, then GH_TOKEN.
- plugin's fetchJSON has a request to GitHub's API's host (githubAPI)
carry it, which covers the git plugins' check and the Plugins page's
topic search. Raw files, npm and every other host never get it, and
source.Do already sends nothing with Authorization to a mirror.
- An answer from GitHub's API that is a rate limit (429, or 403 with
X-RateLimit-Remaining 0, Retry-After or a rate-limit message) is a
ghtoken.Limited: the check's row has Why "limited" and Limited {until,
token} for the page, as the library's skill check already had. A 401
to a request with a token names which token was refused, never the
token.
What was run:
- TestGitPluginCheckCarriesGitHubToken (new, internal/plugin): asks with
no token / GH_TOKEN / GITHUB_TOKEN / Settings in that order of
precedence, a 403 rate limit with and without a token, a 429 with
Retry-After, a refused GH_TOKEN, and a raw-file host that must get no
Authorization. Broken by hand twice: with fetchJSON's Authorize removed
it fails "GH_TOKEN: GitHub's API was asked with Authorization "", want
"Bearer gh-env"" (and the other two sources); with the limit check
removed it fails with Why "registry", Limited nil, "403 Forbidden".
- go test -tags nogui -count=1 ./internal/library ./internal/plugin
(temp HOME, pinned caches): ok, the library's TestGitHubToken*,
TestGitHubRateLimitSaid among them.
- gofmt -l clean; go vet -tags nogui on darwin, GOOS=linux and
GOOS=windows for internal/plugin, library, ghtoken, gui: clean.
- Not tried against the real api.github.com (tests stay off the network).