Internal-ize API endpoint assembly for create-release

This commit is contained in:
2025-05-24 18:15:01 -05:00
parent 2c9cd5b958
commit d4ec677b28

View File

@@ -15,15 +15,6 @@ const API_RELEASE_BACK: &'static str = "/releases";
#[tokio::main] #[tokio::main]
async fn main() -> Result<(), Error> { async fn main() -> Result<(), Error> {
let args = Args::parse(); let args = Args::parse();
let request_url = format!(
"{hostname}{front}{owner}{repo}{back}",
hostname = API_HOSTNAME,
front = API_RELEASE_FRONT,
owner = "robert",
repo = "rcalc",
back = API_RELEASE_BACK
);
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 => {
@@ -45,7 +36,7 @@ async fn main() -> Result<(), Error> {
tag_name: String::from("big-goof"), tag_name: String::from("big-goof"),
target_commitish: String::from("548ceecc7528901a7b4376091b42e410d950affc"), target_commitish: String::from("548ceecc7528901a7b4376091b42e410d950affc"),
}; };
do_create_release(&client, &request_url, submission).await?; do_create_release(&client, submission).await?;
} }
} }
@@ -76,14 +67,21 @@ 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,
endpoint: &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!(
"{hostname}{front}{owner}{repo}{back}",
hostname = API_HOSTNAME,
front = API_RELEASE_FRONT,
owner = "robert",
repo = "rcalc",
back = API_RELEASE_BACK
);
let response = client let response = client
.post(endpoint) .post(request_url)
.header(USER_AGENT, "gt-tools-test-agent") .header(USER_AGENT, "gt-tools-test-agent")
.header(ACCEPT, "application/json") .header(ACCEPT, "application/json")
.header("Authorization", format!("token {}", token)) .header("Authorization", format!("token {}", token))