From 884364038545a90c05ad84d6b05a8ff955806d0e Mon Sep 17 00:00:00 2001 From: Robert Garrett Date: Sat, 24 May 2025 19:33:46 -0500 Subject: [PATCH] Thread the primary args through the operation fn's --- src/main.rs | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/main.rs b/src/main.rs index 951a26a..c6347bb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,7 +8,6 @@ use clap::Parser; use reqwest::Error; use reqwest::header::{ACCEPT, USER_AGENT}; -const API_HOSTNAME: &'static str = "http://localhost:3000"; const API_RELEASE_FRONT: &'static str = "/api/v1/repos/"; const API_RELEASE_BACK: &'static str = "/releases"; @@ -18,7 +17,7 @@ async fn main() -> Result<(), Error> { let client = reqwest::Client::new(); match args.command { gt_tools::cli::Commands::ListReleases => { - let releases = do_list_releases(&client, "robert", "rcalc").await?; + let releases = do_list_releases(&client, &args.gitea_url, &args.repo).await?; for release in releases { println!("{:?}", release); } @@ -39,7 +38,7 @@ async fn main() -> Result<(), Error> { tag_name, target_commitish, }; - do_create_release(&client, submission).await?; + do_create_release(&client, &args.gitea_url, &args.repo, submission).await?; } } @@ -48,12 +47,11 @@ async fn main() -> Result<(), Error> { async fn do_list_releases( client: &reqwest::Client, - owner: &str, + gitea_url: &str, repo: &str, ) -> Result, Error> { let request_url = format!( - "{hostname}{front}{owner}/{repo}{back}", - hostname = API_HOSTNAME, + "{gitea_url}{front}{repo}{back}", front = API_RELEASE_FRONT, back = API_RELEASE_BACK ); @@ -73,17 +71,16 @@ async fn do_list_releases( #[must_use] async fn do_create_release( client: &reqwest::Client, + gitea_url: &str, + repo: &str, submission: CreateReleaseOption, ) -> Result<(), Error> { let token = env::var("RELEASE_KEY_GITEA").expect( "You must set the RELEASE_KEY_GITEA environment variable so the Gitea API can be used.", ); let request_url = format!( - "{hostname}{front}{owner}/{repo}{back}", - hostname = API_HOSTNAME, + "{gitea_url}{front}{repo}{back}", front = API_RELEASE_FRONT, - owner = "robert", - repo = "rcalc", back = API_RELEASE_BACK ); let response = client