Thread the primary args through the operation fn's
This commit is contained in:
17
src/main.rs
17
src/main.rs
@@ -8,7 +8,6 @@ use clap::Parser;
|
|||||||
use reqwest::Error;
|
use reqwest::Error;
|
||||||
use reqwest::header::{ACCEPT, USER_AGENT};
|
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_FRONT: &'static str = "/api/v1/repos/";
|
||||||
const API_RELEASE_BACK: &'static str = "/releases";
|
const API_RELEASE_BACK: &'static str = "/releases";
|
||||||
|
|
||||||
@@ -18,7 +17,7 @@ async fn main() -> Result<(), Error> {
|
|||||||
let client = reqwest::Client::new();
|
let client = reqwest::Client::new();
|
||||||
match args.command {
|
match args.command {
|
||||||
gt_tools::cli::Commands::ListReleases => {
|
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 {
|
for release in releases {
|
||||||
println!("{:?}", release);
|
println!("{:?}", release);
|
||||||
}
|
}
|
||||||
@@ -39,7 +38,7 @@ async fn main() -> Result<(), Error> {
|
|||||||
tag_name,
|
tag_name,
|
||||||
target_commitish,
|
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(
|
async fn do_list_releases(
|
||||||
client: &reqwest::Client,
|
client: &reqwest::Client,
|
||||||
owner: &str,
|
gitea_url: &str,
|
||||||
repo: &str,
|
repo: &str,
|
||||||
) -> Result<Vec<ReleaseInfo>, Error> {
|
) -> Result<Vec<ReleaseInfo>, Error> {
|
||||||
let request_url = format!(
|
let request_url = format!(
|
||||||
"{hostname}{front}{owner}/{repo}{back}",
|
"{gitea_url}{front}{repo}{back}",
|
||||||
hostname = API_HOSTNAME,
|
|
||||||
front = API_RELEASE_FRONT,
|
front = API_RELEASE_FRONT,
|
||||||
back = API_RELEASE_BACK
|
back = API_RELEASE_BACK
|
||||||
);
|
);
|
||||||
@@ -73,17 +71,16 @@ async fn do_list_releases(
|
|||||||
#[must_use]
|
#[must_use]
|
||||||
async fn do_create_release(
|
async fn do_create_release(
|
||||||
client: &reqwest::Client,
|
client: &reqwest::Client,
|
||||||
|
gitea_url: &str,
|
||||||
|
repo: &str,
|
||||||
submission: CreateReleaseOption,
|
submission: CreateReleaseOption,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
let token = env::var("RELEASE_KEY_GITEA").expect(
|
let token = env::var("RELEASE_KEY_GITEA").expect(
|
||||||
"You must set the RELEASE_KEY_GITEA environment variable so the Gitea API can be used.",
|
"You must set the RELEASE_KEY_GITEA environment variable so the Gitea API can be used.",
|
||||||
);
|
);
|
||||||
let request_url = format!(
|
let request_url = format!(
|
||||||
"{hostname}{front}{owner}/{repo}{back}",
|
"{gitea_url}{front}{repo}{back}",
|
||||||
hostname = API_HOSTNAME,
|
|
||||||
front = API_RELEASE_FRONT,
|
front = API_RELEASE_FRONT,
|
||||||
owner = "robert",
|
|
||||||
repo = "rcalc",
|
|
||||||
back = API_RELEASE_BACK
|
back = API_RELEASE_BACK
|
||||||
);
|
);
|
||||||
let response = client
|
let response = client
|
||||||
|
|||||||
Reference in New Issue
Block a user