Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/cmds/install.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use anyhow::{Context, Result};
use clap::Parser;
use flate2::read::GzDecoder;
use octocrab::Octocrab;
use octocrab::models::repos::Asset;
use octocrab::models::repos::Release;
use reqwest::Client;
Expand Down Expand Up @@ -180,8 +179,9 @@ pub async fn download_tool_from_asset(tool: &Tool, asset: &Asset, config: &Confi
async fn find_matching_release(
tool: &Tool,
requested: &VersionReq,
config: &Config,
) -> anyhow::Result<Option<(Version, Release)>> {
let octocrab = Octocrab::builder().build()?;
let octocrab = crate::manifest::build_octocrab(config)?;
let owner = tool.repo_owner.clone();
let repo = tool.repo_name.clone();
let repo = octocrab.repos(owner, repo);
Expand Down Expand Up @@ -219,7 +219,7 @@ async fn run_github_release_installer(
) -> anyhow::Result<()> {
println!("\n> Installing {} at version {}", tool.name, requested);

let Some((version, release)) = find_matching_release(tool, requested).await? else {
let Some((version, release)) = find_matching_release(tool, requested, config).await? else {
return Err(anyhow::anyhow!("No release found for {}", tool.name));
};

Expand Down
9 changes: 9 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ struct Cli {
#[arg(global = true, short, long, env = "TX3_CHANNEL")]
channel: Option<String>,

#[arg(global = true, long, env = "GITHUB_TOKEN", hide = true)]
github_token: Option<String>,

#[command(subcommand)]
command: Option<Commands>,
}
Expand Down Expand Up @@ -57,9 +60,14 @@ impl Commands {
pub struct Config {
root_dir: Option<PathBuf>,
channel: Option<String>,
github_token: Option<String>,
}

impl Config {
pub fn github_token(&self) -> Option<&str> {
self.github_token.as_deref().filter(|t| !t.is_empty())
}

pub fn default_root_dir() -> Result<PathBuf> {
let mut path = if cfg!(target_os = "windows") {
dirs::data_local_dir()
Expand Down Expand Up @@ -164,6 +172,7 @@ async fn main() -> anyhow::Result<()> {
let config = Config {
root_dir: cli.root_dir,
channel: cli.channel,
github_token: cli.github_token,
};

let skip_banner = cli.command.as_ref().map_or(false, |c| c.skip_banner());
Expand Down
14 changes: 11 additions & 3 deletions src/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@ use tokio::fs;

use crate::Config;

pub fn build_octocrab(config: &Config) -> anyhow::Result<Octocrab> {
let mut builder = Octocrab::builder();

if let Some(token) = config.github_token() {
builder = builder.personal_token(token.to_string());
}

builder.build().context("building octocrab client")
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum Installer {
GithubRelease,
Expand Down Expand Up @@ -103,9 +113,7 @@ pub async fn download_remote_manifest(
config: &Config,
explicit_tag: Option<&str>,
) -> anyhow::Result<()> {
let octocrab = Octocrab::builder()
.build()
.context("building octocrab client")?;
let octocrab = build_octocrab(config)?;

let repo = octocrab.repos("tx3-lang", "toolchain");

Expand Down
Loading