MCPcopy Create free account
hub / github.com/1jehuang/jcode / github_public_api_token

Function github_public_api_token

crates/jcode-base/src/github.rs:21–34  ·  view source on GitHub ↗

Resolve a GitHub token for authenticated public API access. Order: `GH_TOKEN`/`GITHUB_TOKEN` env vars, then a `gh auth token` subprocess lookup cached once per process (including a cached miss, so the subprocess is spawned at most once). Returns `None` when no token is available; callers should proceed unauthenticated in that case. Only send this token to `api.github.com` public read endpoints.

()

Source from the content-addressed store, hash-verified

19///
20/// Only send this token to `api.github.com` public read endpoints.
21pub fn github_public_api_token() -> Option<String> {
22 let env_token = ["GH_TOKEN", "GITHUB_TOKEN"].iter().find_map(|name| {
23 std::env::var(name)
24 .ok()
25 .map(|token| token.trim().to_string())
26 .filter(|token| !token.is_empty())
27 });
28 if env_token.is_some() {
29 return env_token;
30 }
31
32 static GH_CLI_TOKEN: OnceLock<Option<String>> = OnceLock::new();
33 GH_CLI_TOKEN.get_or_init(gh_cli_token).clone()
34}
35
36fn gh_cli_token() -> Option<String> {
37 if !crate::auth::command_exists("gh") {

Callers 2

github_api_requestFunction · 0.85
download_browser_binaryFunction · 0.85

Calls 5

iterMethod · 0.80
filterMethod · 0.80
okMethod · 0.45
is_emptyMethod · 0.45
cloneMethod · 0.45

Tested by

no test coverage detected