From f1da1b508afb26c302bf45e49ce95b090534b9b7 Mon Sep 17 00:00:00 2001 From: Robert Garrett Date: Sat, 24 May 2025 15:14:53 -0500 Subject: [PATCH] Releases can now be created... sorta The API token is read from the environment variable `RELEASE_KEY_GITEA`. "GITEA" is on the end because Gitea itself will refuse to allow users to configure Act variables starting with the name "GITEA_". All information about the release is hard-coded right now. I just needed to see it hit the API and appear on the Gitea page. Hooking up the extra options is up next. --- src/cli.rs | 4 ++++ src/lib.rs | 25 ++++++++++++++++++++++++- src/main.rs | 18 ++++++++++++++++++ 3 files changed, 46 insertions(+), 1 deletion(-) diff --git a/src/cli.rs b/src/cli.rs index ebb3a52..d565e56 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -15,4 +15,8 @@ pub struct Args { #[derive(Subcommand, Debug)] pub enum Commands { ListReleases, + CreateRelease { + #[arg()] + name: String, + }, } diff --git a/src/lib.rs b/src/lib.rs index 22cd116..a883cf9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,4 @@ -use serde::Deserialize; +use serde::{Deserialize, Serialize}; pub mod cli; @@ -35,3 +35,26 @@ pub struct Author { full_name: String, email: String, } + +#[derive(Serialize, Debug)] +pub struct CreateReleaseOption { + body: String, + draft: bool, + name: String, + prerelease: bool, + tag_name: String, + target_commitish: String, +} + +impl CreateReleaseOption { + pub fn new(name: String) -> Self { + Self{ + body: String::from("hard-coded test body"), + draft: true, + name, + prerelease: true, + tag_name: String::from("hard-coded-test"), + target_commitish: String::from("3171c892480c46976106fa465d04fdb7e734dd53") + } + } +} diff --git a/src/main.rs b/src/main.rs index 58aad99..bc02b7e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,8 @@ +use gt_tools::CreateReleaseOption; use gt_tools::{ReleaseInfo, cli::Args}; +use std::env; + use clap::Parser; use reqwest::Error; @@ -27,6 +30,21 @@ async fn main() -> Result<(), Error> { println!("{:?}", body_text); } + gt_tools::cli::Commands::CreateRelease { name } => { + 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 body = CreateReleaseOption::new(name); + let response = client + .post(request_url) + .header(USER_AGENT, "gt-tools-test-agent") + .header(ACCEPT, "application/json") + .header("Authorization", format!("token {}", token)) + .json(&body) + .send() + .await?; + + println!("{:?}", response.text().await?); + } } Ok(())