c76bcaea7a3ab1f7aafbb55f901affaff4e55d16
4
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
dc1af8231b |
ghtoken: a Settings token GitHub refuses is said, and requests go without one (#3926)
A GitHub token in Settings → Network and sharing that GitHub refused (401, expired or revoked) failed every plugin and skill check, so a stale token was worse than none. Now it is treated as an environment token already was: the request is asked again without it, the token isn't sent again while magpie runs or until the field changes, and the anonymous answer (60 an hour) is the one taken. This overturns the package comment and TestSettingsTokenRefusedStaysAnError: the token being the user's choice is a reason to tell them, not to fail the check. The page stays honest about it: - Settings › Network and sharing still shows the token, masked, with Remove, and says in red that GitHub refused it and requests go without one until it is replaced (/api/settings githubTokenRefused). Before, a refused token simply read as none being set. - After a Settings token's refusal requests go anonymous, not with GITHUB_TOKEN/GH_TOKEN: the user put the Settings one ahead of those, and the page says "without one". Patch by MYCF711 (fix/settings-token-fallback, 7d93f1b5): the ghtoken change and its tests. Changed from it: the notice is in Settings' row, where the token lives, instead of the patch's Plugins page note, which cost ~630 bytes of core script the budget (28 bytes of room at |
||
|
|
0f044e9447 |
plugins: a GITHUB_TOKEN GitHub refuses is dropped for anonymous requests, not shown as an error (till on Discord)
till's Plugins page said "无法连接 GitHub: GitHub refused GITHUB_TOKEN (no GitHub token is set in Settings → Network and sharing)". ghtoken.Token falls back to the environment's GITHUB_TOKEN / GH_TOKEN, and a stale one there made every GitHub read fail, though GitHub serves the same reads without a token. ghtoken.Do now sends a GitHub API request with the token. When the token came from the environment and GitHub answers 401, it remembers that token as refused for the rest of the process (Token() skips it, so GH_TOKEN is still tried after a refused GITHUB_TOKEN, and Settings no longer shows it) and asks once more without Authorization, returning that answer. A token set in Settings is never dropped: its 401 is still Refused()'s error. An anonymous rate limit after the drop is said by LimitedBy as before. Every caller goes through it: plugin fetchJSONFrom (tagged-repo search, git plugin checks, githubHead) and getURLFrom (Bun), and library apiGet, skills fetch, skilltree fetchBlob and latestRTK via doGitHub. internal/davsync/github.go stays strict: its token is the one the user gave sync to write a private repo, outside ghtoken, and an anonymous retry can't write there, so it would only hide why sync failed. Tests (httptest only): ghtoken_test covers an env token refused then asked again without, not sent again (and GH_TOKEN tried next), a Settings token refused stays an error, an env token refused then an anonymous rate limit is reported, and another host untouched. plugin TestTaggedReposStaleEnvTokenDropped is till's case: TaggedRepos with GITHUB_TOKEN=stale-till lists 7 repos, no error. github_token_test and library TestGitHubRateLimitSaid now expect the env token dropped and the Settings token still refused. Broken by hand, each red: (a) no anonymous retry: every new env test, the plugin and library tests red, and TestTaggedReposStaleEnvTokenDropped shows till's exact error; (b) no memory of the refusal: NotSentAgain, the plugin and library tests red; (c) a Settings token also retried: SettingsTokenRefusedStaysAnError, the plugin and library tests red. Run on the commit before the rebase (base |
||
|
|
334bb182e9 |
plugin: Bun's release check asks GitHub's API with the GitHub token from Settings too (#1942, bingqilinweimaotai)
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. |
||
|
|
431707944e |
plugin, library: Check for updates asks GitHub with the GitHub token from Settings, and says when GitHub's rate limit is used up (#1942, bingqilinweimaotai)
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).
|