mirror of
https://github.com/Llewellynvdm/starship.git
synced 2024-12-26 03:27:30 +00:00
feat(bug-report): ask for confirmation before opening issue (#4543)
* feat(bug-report): ask for confirmation before opening issue * Apply suggestions from code review Co-authored-by: Thomas O'Donnell <andytom@users.noreply.github.com> Co-authored-by: Thomas O'Donnell <andytom@users.noreply.github.com>
This commit is contained in:
parent
df37e8d40c
commit
8bb9038431
@ -1,5 +1,6 @@
|
|||||||
use crate::shadow;
|
use crate::shadow;
|
||||||
use crate::utils::{self, exec_cmd};
|
use crate::utils::{self, exec_cmd};
|
||||||
|
use nu_ansi_term::Style;
|
||||||
|
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
@ -17,16 +18,33 @@ pub fn create() {
|
|||||||
starship_config: get_starship_config(),
|
starship_config: get_starship_config(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let link = make_github_issue_link(environment);
|
let issue_body = get_github_issue_body(&environment);
|
||||||
|
|
||||||
if open::that(&link).is_ok() {
|
println!(
|
||||||
println!("Take a look at your browser. A GitHub issue has been populated with your configuration.");
|
"{}\n{issue_body}\n\n",
|
||||||
println!("If your browser has failed to open, please click this link:\n");
|
Style::new().bold().paint("Generated bug report:")
|
||||||
|
);
|
||||||
|
println!("Forward the pre-filled report above to GitHub in your browser?");
|
||||||
|
println!("{} To avoid any sensitive data from being exposed, please review the included information before proceeding. Data forwarded to GitHub is subject to GitHub's privacy policy.", Style::new().bold().paint("Warning:"));
|
||||||
|
println!(
|
||||||
|
"Enter `{}` to accept, or anything else to decline, and `{}` to confirm your choice:\n",
|
||||||
|
Style::new().bold().paint("y"),
|
||||||
|
Style::new().bold().paint("Enter key")
|
||||||
|
);
|
||||||
|
|
||||||
|
let mut input = String::new();
|
||||||
|
let _ = std::io::stdin().read_line(&mut input);
|
||||||
|
|
||||||
|
if input.trim().to_lowercase() == "y" {
|
||||||
|
let link = make_github_issue_link(&issue_body);
|
||||||
|
if let Err(e) = open::that(&link) {
|
||||||
|
println!("Failed to open issue report in your browser: {}", e);
|
||||||
|
println!("Please copy the above report and open an issue manually, or try opening the following link:\n{link}");
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
println!("Click this link to create a GitHub issue populated with your configuration:\n");
|
println!("Will not open an issue in your browser! Please copy the above report and open an issue manually.");
|
||||||
}
|
}
|
||||||
|
println!("Thanks for using the Starship bug report tool!");
|
||||||
println!("{link}");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const UNKNOWN_SHELL: &str = "<unknown shell>";
|
const UNKNOWN_SHELL: &str = "<unknown shell>";
|
||||||
@ -50,7 +68,7 @@ fn get_pkg_branch_tag() -> &'static str {
|
|||||||
shadow::BRANCH
|
shadow::BRANCH
|
||||||
}
|
}
|
||||||
|
|
||||||
fn make_github_issue_link(environment: Environment) -> String {
|
fn get_github_issue_body(environment: &Environment) -> String {
|
||||||
let shell_syntax = match environment.shell_info.name.as_ref() {
|
let shell_syntax = match environment.shell_info.name.as_ref() {
|
||||||
"powershell" | "pwsh" => "pwsh",
|
"powershell" | "pwsh" => "pwsh",
|
||||||
"fish" => "fish",
|
"fish" => "fish",
|
||||||
@ -60,7 +78,7 @@ fn make_github_issue_link(environment: Environment) -> String {
|
|||||||
_ => "bash",
|
_ => "bash",
|
||||||
};
|
};
|
||||||
|
|
||||||
let body = urlencoding::encode(&format!("#### Current Behavior
|
format!("#### Current Behavior
|
||||||
<!-- A clear and concise description of the behavior. -->
|
<!-- A clear and concise description of the behavior. -->
|
||||||
|
|
||||||
#### Expected Behavior
|
#### Expected Behavior
|
||||||
@ -109,13 +127,16 @@ fn make_github_issue_link(environment: Environment) -> String {
|
|||||||
build_rust_channel = shadow::BUILD_RUST_CHANNEL,
|
build_rust_channel = shadow::BUILD_RUST_CHANNEL,
|
||||||
build_time = shadow::BUILD_TIME,
|
build_time = shadow::BUILD_TIME,
|
||||||
shell_syntax = shell_syntax,
|
shell_syntax = shell_syntax,
|
||||||
))
|
)
|
||||||
.replace("%20", "+");
|
}
|
||||||
|
|
||||||
|
fn make_github_issue_link(body: &str) -> String {
|
||||||
|
let escaped = urlencoding::encode(body).replace("%20", "+");
|
||||||
|
|
||||||
format!(
|
format!(
|
||||||
"https://github.com/starship/starship/issues/new?template={}&body={}",
|
"https://github.com/starship/starship/issues/new?template={}&body={}",
|
||||||
urlencoding::encode("Bug_report.md"),
|
urlencoding::encode("Bug_report.md"),
|
||||||
body
|
escaped
|
||||||
)
|
)
|
||||||
.chars()
|
.chars()
|
||||||
.take(GITHUB_CHAR_LIMIT)
|
.take(GITHUB_CHAR_LIMIT)
|
||||||
@ -259,7 +280,8 @@ mod tests {
|
|||||||
starship_config: "No Starship config".to_string(),
|
starship_config: "No Starship config".to_string(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let link = make_github_issue_link(environment);
|
let body = get_github_issue_body(&environment);
|
||||||
|
let link = make_github_issue_link(&body);
|
||||||
|
|
||||||
assert!(link.contains(clap::crate_version!()));
|
assert!(link.contains(clap::crate_version!()));
|
||||||
assert!(link.contains("Linux"));
|
assert!(link.contains("Linux"));
|
||||||
|
Loading…
Reference in New Issue
Block a user