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.
This commit is contained in:
parent
5c3f3c65f9
commit
5d20316c57
|
|
@ -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..."
|
||||
"<!--\n\
|
||||
Enter a description...\n\
|
||||
-->"
|
||||
} else {
|
||||
description
|
||||
};
|
||||
|
|
@ -500,10 +503,28 @@ fn prompt_issue(
|
|||
}
|
||||
}
|
||||
|
||||
let description: String = lines.collect::<Vec<&str>>().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::<Vec<&str>>().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)))
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue