Skip to content

Commit

Permalink
Make flakehub-flake-name truly optional
Browse files Browse the repository at this point in the history
  • Loading branch information
cole-h committed May 9, 2024
1 parent 00e22a6 commit 3d9bcd1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
14 changes: 11 additions & 3 deletions magic-nix-cache/src/flakehub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub async fn init_cache(
flakehub_api_server: &Url,
flakehub_api_server_netrc: &Path,
flakehub_cache_server: &Url,
flakehub_flake_name: &str,
flakehub_flake_name: Option<String>,
store: Arc<NixStore>,
) -> Result<State> {
// Parse netrc to get the credentials for api.flakehub.com.
Expand Down Expand Up @@ -121,10 +121,18 @@ pub async fn init_cache(

// Get the cache UUID for this project.
let cache_name = {
let url = flakehub_api_server
.join(&format!("project/{}", flakehub_flake_name))
let mut url = flakehub_api_server
.join("project")
.map_err(|_| Error::Config(format!("bad URL '{}'", flakehub_api_server)))?;

if let Some(flakehub_flake_name) = flakehub_flake_name {
if !flakehub_flake_name.is_empty() {
url = flakehub_api_server
.join(&format!("project/{}", flakehub_flake_name))
.map_err(|_| Error::Config(format!("bad URL '{}'", flakehub_api_server)))?;
}
}

let response = reqwest::Client::new()
.get(url.to_owned())
.header("User-Agent", USER_AGENT)
Expand Down
12 changes: 2 additions & 10 deletions magic-nix-cache/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,23 +164,15 @@ async fn main_cli() -> Result<()> {
let flakehub_api_server_netrc = args
.flakehub_api_server_netrc
.ok_or_else(|| anyhow!("--flakehub-api-server-netrc is required"))?;
let flakehub_flake_name = args
.flakehub_flake_name
.ok_or_else(|| {
tracing::debug!(
"--flakehub-flake-name was not set, inferring from $GITHUB_REPOSITORY env var"
);
std::env::var("GITHUB_REPOSITORY")
})
.map_err(|_| anyhow!("--flakehub-flake-name and $GITHUB_REPOSITORY were both unset"))?;
let flakehub_flake_name = args.flakehub_flake_name;

match flakehub::init_cache(
&args
.flakehub_api_server
.ok_or_else(|| anyhow!("--flakehub-api-server is required"))?,
&flakehub_api_server_netrc,
&flakehub_cache_server,
&flakehub_flake_name,
flakehub_flake_name,
store.clone(),
)
.await
Expand Down

0 comments on commit 3d9bcd1

Please sign in to comment.