Add confirmation prompt before commiting a release

This commit is contained in:
Guilhem Lavaux 2025-06-09 16:27:24 +02:00
parent 40e51f00d7
commit affb7fbd01

View file

@ -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,7 +131,10 @@ 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| {
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()
})?;