From affb7fbd0198bcee5b9837aaf49503087ec8627b Mon Sep 17 00:00:00 2001 From: Guilhem Lavaux Date: Mon, 9 Jun 2025 16:27:24 +0200 Subject: [PATCH] Add confirmation prompt before commiting a release --- src/main.rs | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/src/main.rs b/src/main.rs index a8ef6bb..453b39d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,6 +4,7 @@ use forgejo_api::Auth::Token; use forgejo_api::Forgejo; use forgejo_api::structs::CreateReleaseOption; use url::Url; +use std::io; pub mod config; @@ -36,9 +37,7 @@ enum ReleaseSubCommands { }, /// Another sub-subcommand - List { - alias: String, - }, + List { alias: String }, } async fn handle_new_release( @@ -69,10 +68,23 @@ async fn handle_new_release( e.to_string() })?; + if target.is_none() { + println!("Target not provided for creating a release."); + println!("Please confirm by typing 'yes' that you want to create automatically with the latest commit."); + + let mut input = String::new(); + io::stdin() + .read_line(&mut input) + .expect("Failed to read line"); + if input.trim().to_lowercase() != "yes" { + return Err("Release creation cancelled by user.".to_string()); + } + } + let option = CreateReleaseOption { tag_name: tag.to_string(), name: Some(format!("{}", tag)), - body: Some(format!("Release notes for {}", tag)), + body: Some(format!("Release {}", tag)), hide_archive_links: Some(false), target_commitish: target.clone(), draft: None, @@ -119,10 +131,13 @@ async fn handle_list_releases(config: &config::Config, alias: &str) -> Result<() pre_release: None, limit: Some(100), }; - let result_query = forgejo.repo_list_releases(&repo.owner, &repo.repo, query).await.map_err(|e| { - eprintln!("Failed to list releases: {}", e); - e.to_string() - })?; + let result_query = forgejo + .repo_list_releases(&repo.owner, &repo.repo, query) + .await + .map_err(|e| { + eprintln!("Failed to list releases: {}", e); + e.to_string() + })?; for release in result_query.1 { println!(