From 5d20316c57a142bafef7123e19a8889c37321673 Mon Sep 17 00:00:00 2001 From: Slack Coder Date: Mon, 5 Jun 2023 13:42:22 -0500 Subject: [PATCH] cli: Fix accidental issue creation When a user is creating an issue via the editor, it is very easy to accidentally create an issue. To fix this, make the default description also 'empty' and bail out if either it or the title are empty. Retain the default 'description' message by providing it as a comment. --- radicle-cli/src/commands/issue.rs | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/radicle-cli/src/commands/issue.rs b/radicle-cli/src/commands/issue.rs index 68d356ed..c6675d12 100644 --- a/radicle-cli/src/commands/issue.rs +++ b/radicle-cli/src/commands/issue.rs @@ -1,5 +1,6 @@ #![allow(clippy::or_fun_call)] use std::ffi::OsString; +use std::io; use std::str::FromStr; use anyhow::{anyhow, Context as _}; @@ -464,7 +465,9 @@ fn prompt_issue( title }; let description = if description.is_empty() { - "Enter a description..." + "" } else { description }; @@ -500,10 +503,28 @@ fn prompt_issue( } } - let description: String = lines.collect::>().join("\n"); - let meta: Metadata = + let mut meta: Metadata = serde_yaml::from_str(&meta).context("failed to parse yaml front-matter")?; + meta.title = meta.title.trim().to_string(); + if meta.title.is_empty() { + return Err(io::Error::new( + io::ErrorKind::InvalidInput, + "an issue title must be provided", + ) + .into()); + } + + let description: String = lines.collect::>().join("\n"); + let description = term::format::strip_comments(&description); + if description.is_empty() { + return Err(io::Error::new( + io::ErrorKind::InvalidInput, + "an issue description must be provided", + ) + .into()); + } + Ok(Some((meta, description))) }