Skip to content

Commit

Permalink
fix: use GITHUB_API_TOKEN or GITHUB_TOKEN
Browse files Browse the repository at this point in the history
---------

Co-authored-by: mise[bot] <[email protected]>
  • Loading branch information
jdx and mise-en-dev committed Oct 25, 2024
1 parent 1e3cbc3 commit 444358f
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 6 deletions.
4 changes: 3 additions & 1 deletion src/backend/ubi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ impl Backend for UbiBackend {
fn install_version_impl(&self, ctx: &InstallContext) -> eyre::Result<()> {
let mut v = ctx.tv.version.to_string();

if let Err(_err) = github::get_release(self.name(), &ctx.tv.version) {
if let Err(err) = github::get_release(self.name(), &ctx.tv.version) {
warn!("err: {}", err);
// this can fail with a rate limit error or 404, either way, try prefixing and if it fails, try without the prefix
// if http::error_code(&err) == Some(404) {
debug!("no tag found for {}, try prefixing with 'v'", ctx.tv);
Expand All @@ -76,6 +77,7 @@ impl Backend for UbiBackend {
.install_dir(path_with_bin);

if let Some(token) = &*GITHUB_TOKEN {
warn!("Using GITHUB_TOKEN={}", token);
builder = builder.github_token(token);
}

Expand Down
4 changes: 2 additions & 2 deletions src/cli/self_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ impl SelfUpdate {

fn fetch_releases(&self) -> Result<Vec<Release>> {
let mut releases = ReleaseList::configure();
if let Some(token) = &*env::GITHUB_API_TOKEN {
if let Some(token) = &*env::GITHUB_TOKEN {
releases.auth_token(token);
}
let releases = releases
Expand All @@ -82,7 +82,7 @@ impl SelfUpdate {
.map(|v| format!("v{}", v))?;
let target = format!("{}-{}", *OS, *ARCH);
let mut update = Update::configure();
if let Some(token) = &*env::GITHUB_API_TOKEN {
if let Some(token) = &*env::GITHUB_TOKEN {
update.auth_token(token);
}
if self.force || self.version.is_some() {
Expand Down
2 changes: 0 additions & 2 deletions src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,6 @@ pub static PATH_NON_PRISTINE: Lazy<Vec<PathBuf>> = Lazy::new(|| match var(&*PATH
Err(_) => vec![],
});
pub static DIRENV_DIFF: Lazy<Option<String>> = Lazy::new(|| var("DIRENV_DIFF").ok());
#[allow(unused)]
pub static GITHUB_API_TOKEN: Lazy<Option<String>> = Lazy::new(|| var("GITHUB_API_TOKEN").ok());
pub static GITHUB_TOKEN: Lazy<Option<String>> = Lazy::new(|| {
var("GITHUB_TOKEN")
.or_else(|_| var("GITHUB_API_TOKEN"))
Expand Down
3 changes: 2 additions & 1 deletion src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ impl Client {
debug!("GET {}", &url);
let mut req = self.reqwest.get(url.clone());
if url.host_str() == Some("api.github.com") {
if let Some(token) = &*env::GITHUB_API_TOKEN {
if let Some(token) = &*env::GITHUB_TOKEN {
dbg!("Using GitHub token");
req = req.header("authorization", format!("token {}", token));
}
}
Expand Down

0 comments on commit 444358f

Please sign in to comment.