Skip to content

Commit

Permalink
fix(GitHubSource): do not require full AuthManifest
Browse files Browse the repository at this point in the history
Co-authored-by: Filip Tibell <filip.tibell@gmail.com>
  • Loading branch information
sasial-dev and filiptibell committed Sep 5, 2022
1 parent 3437ec6 commit 76e0838
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
5 changes: 2 additions & 3 deletions src/tool_source/github.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use reqwest::{
use semver::Version;
use serde::{Deserialize, Serialize};

use crate::auth::AuthManifest;
use crate::tool_id::ToolId;
use crate::tool_name::ToolName;
use crate::tool_source::Asset;
Expand All @@ -23,10 +22,10 @@ pub struct GitHubSource {
}

impl GitHubSource {
pub fn new(auth: Option<AuthManifest>) -> Self {
pub fn new(token: Option<String>) -> Self {
Self {
client: Client::new(),
token: auth.map(|t| t.github).flatten()
token
}
}

Expand Down
14 changes: 12 additions & 2 deletions src/tool_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,12 @@ impl ToolStorage {
log::info!("Installing tool: {}", spec);

log::debug!("Fetching GitHub releases...");
let github = self.github.get_or_init(|| GitHubSource::new(self.auth));
let github = self.github.get_or_init(|| {
GitHubSource::new(match &self.auth {
Some(auth) => auth.github.clone(),
None => None,
})
});
let mut releases = github.get_all_releases(spec.name())?;
releases.sort_by(|a, b| a.version.cmp(&b.version).reverse());

Expand Down Expand Up @@ -237,7 +242,12 @@ impl ToolStorage {
log::info!("Installing tool: {id}");

log::debug!("Fetching GitHub release...");
let github = self.github.get_or_init(|| GitHubSource::new(self.auth));
let github = self.github.get_or_init(|| {
GitHubSource::new(match &self.auth {
Some(auth) => auth.github.clone(),
None => None,
})
});
let release = github.get_release(id)?;

let mut compatible_assets = self.get_compatible_assets(&release);
Expand Down

0 comments on commit 76e0838

Please sign in to comment.