…, or else of the IDE's GitHub account, when GITHUB_TOKEN and GH_TOKEN aren't set (#2230)
Fixes #2188 (part 1, a GitHub token from the IDE). Part 2 was #2202.
## What
A `github` download sent a token only from `GITHUB_TOKEN` or `GH_TOKEN`.
An IDE started from the Windows Start menu or a Linux desktop launcher
doesn't see a token exported in a shell profile, so it stayed at the
GitHub API's 60 requests an hour. An IDE started from the macOS Dock
does read the login shell's environment. The rate-limit message only
suggested `GITHUB_TOKEN`.
## Change
**Precedence** (`GitHubAssetFetcher.findToken`). A blank value falls
through to the next source, and a source that fails is logged and
skipped.
1. `GITHUB_TOKEN`, then `GH_TOKEN`, as before. The environment overrides
stored configuration, as with the GitHub CLI.
2. **The LSP4IJ setting:** a GitHub token in *Settings | Languages &
Frameworks | Language Servers (LSP4IJ)*.
3. **The IDE's GitHub account:** the first github.com account in
*Settings | Version Control | GitHub*.
4. Otherwise no token, as before.
**The setting:**
- `GitHubTokenSettings` keeps it for the whole IDE in the Password Safe,
under `generateServiceName("LSP4IJ", "GitHub token")`, never in XML.
- The UI is `GitHubTokenField`, a password field with a help line.
- The Password Safe is read and written off the EDT; on 2026.3 it is
`@RequiresBackgroundThread`. An empty field removes the stored token.
**The GitHub account:**
- It's read through an optional dependency on the bundled GitHub plugin:
`plugin-github.xml`, with `org.jetbrains.plugins.github` added to
`platformBundledPlugins`.
- Only the Kotlin class `GitHubPluginAccountTokenProvider` refers to
GitHub-plugin classes, so without the plugin the source is simply
absent.
- Only accounts whose server's API URL is the download's are used: a
GitHub Enterprise token never goes to github.com.
- The token is read with `GHAccountManager.findCredentials` in
`runBlockingCancellable`, under the installer's progress.
**Messages:** a token is named by its source, e.g. "the token of the
LSP4IJ settings" or "the token of the IDE's GitHub account <login>". A
refused token from any source is retried without it, and the
notification says why, as for the environment variable since #2202. The
rate-limit hint now names the setting first. The tests check that the
token appears in neither the console, the log, nor the notification.
**Docs:** a "GitHub token" section in
`docs/UserDefinedLanguageServerTemplate.md`. It covers the three sources
and their order, the setting (with a screenshot), what the
failed-install notification says, and that a token doesn't make a
private repository's assets downloadable. The asset download sends no
token.
**API note:**
- `GHAccountManager` is public on 2024.2 and 2025.3, but
`@ApiStatus.Internal` on 2026.3, where the GitHub plugin has no public
way to read an account's token. Its alternatives there are internal too,
require the EDT, or are deprecated.
- The plugin verifier says Compatible on 2024.2 and 2026.3. It reports
one experimental usage on 2024.2 (`runBlockingCancellable`) and one
internal usage on 2026.3 (`GHAccountManager`, 4 references). The
deprecated-usage counts are unchanged.
Not in this PR:
- **Account choice:** with several github.com accounts, the first in the
settings order is used, not a project's default. `GHAccountsUtil`
requires the EDT, and the fetcher has no project.
- **Notification screenshot:** it couldn't be rendered offscreen, so it
will be added from a running IDE. A TODO in the docs marks its place.
## Tests
- `GitHubAssetFetcherTest`: precedence, fall-through, refusal and retry,
and naming of the source.
- `GitHubDownloadTaskTest`: the notification and the log never show the
token.
- `GitHubPluginAccountTokenProviderTest`: a real integration test with
github.com and GitHub Enterprise accounts, through `GHAccountManager`
and the test application's in-memory Password Safe.
- `GitHubTokenFieldTest`: the field stores the token in the Password
Safe, loads it back, and an empty field removes it.
Every wait uses a future with a bound, and there are no fixed sleeps.
Red-green, by mutation: an environment-only lookup gives 18 failures,
the account before the setting gives 3, and the setting before the
environment gives 1.
`installation.*` and `settings.*` pass headless on IC 2024.2, 2025.3 and
IU 2026.3: 310 tests each, 0 failures. The full suite passes on 2024.2
and IU 2026.3: 2,487 tests, 0 failures, with the 7 skipped tests that
were already disabled.
## Behaviour change
| Before | After |
|---|---|
| A `github` download sent a token only from `GITHUB_TOKEN`/`GH_TOKEN`,
and the rate-limit message suggested only `GITHUB_TOKEN` | Without those
variables, it sends the token of the LSP4IJ settings (Password Safe), or
else of the IDE's first github.com account. The console, log and
notification name the source, a refused token is retried without it, and
the rate-limit message names the setting |
Part of #2188 (part 2: the rate-limit message in the notification of a failed download). Part 1, a GitHub token from the IDE, is still open.
What
When the GitHub API's rate limit stops a
githubdownload whose installer has no fallbackurl, the installation fails. The console says why: when the limit resets, and that a token raises it. The notification didn't. It said "Unable to retrieve the download URL for your platform … define a valid url or github.asset", which is wrong in that case.Change
Reporter: a new default no-op method,addFailureReason(String). It's backward compatible.GitHubAssetFetcher.fetchReleasesJson: collects the messages it already explains in the console, and reports them only when the releases can't be loaded. These are the rate limit, and a token GitHub refuses: expired or bad (401), not authorized by SAML single sign-on, missing permissions, a generic 403, or a repository not found (404).DownloadTask:Reporterrecord, because the fetchers are shared per repository.urlis unchanged.docs/UserDefinedLanguageServerTemplate.mdsays that the notification now gives the reason too.#2195 changes the same
downloadUrl == nullblock ofDownloadTask. The newifsits before it, so whichever merges later is rebased trivially.Not in this PR:
Tests
Six new tests in
GitHubDownloadTaskTest, with theLocalHttpServerfake of the GitHub API. They capture the real notification throughServerInstallerManager.installandNotifications.TOPIC.url: the notification has the rate-limit message.url: the same success as before, with no rate-limit text.&, then 404: HTML-escaped.Red-green:
The
installation.*tests pass on IC 2024.2, 2025.3 and IU 2026.3: 192 tests each, with 0 failures or skipped.Behaviour change
githubdownload withouturlthat the rate limit, a refused token or a missing repository stopped fails with a notification that asks for a validurlorgithub.asset