diff options
author | David Knaack <davidkna@users.noreply.github.com> | 2022-11-25 17:44:25 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-25 17:44:25 +0100 |
commit | 8bb9038431cd369e953ca156ed09aabd7c2ba326 (patch) | |
tree | 557b82d0e9243b9fbb803205a1ae838ba1afcb1a /src/bug_report.rs | |
parent | df37e8d40c7b3556f8428ce29c53f2882af2ce25 (diff) |
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>
Diffstat (limited to 'src/bug_report.rs')
-rw-r--r-- | src/bug_report.rs | 50 |
1 files changed, 36 insertions, 14 deletions
diff --git a/src/bug_report.rs b/src/bug_report.rs index 8c6ac98f4..9d819e4be 100644 --- a/src/bug_report.rs +++ b/src/bug_report.rs @@ -1,5 +1,6 @@ use crate::shadow; use crate::utils::{self, exec_cmd}; +use nu_ansi_term::Style; use std::fs; use std::path::PathBuf; @@ -17,16 +18,33 @@ pub fn create() { starship_config: get_starship_config(), }; - let link = make_github_issue_link(environment); - - if open::that(&link).is_ok() { - println!("Take a look at your browser. A GitHub issue has been populated with your configuration."); - println!("If your browser has failed to open, please click this link:\n"); + let issue_body = get_github_issue_body(&environment); + + println!( + "{}\n{issue_body}\n\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 { - 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!("{link}"); + println!("Thanks for using the Starship bug report tool!"); } const UNKNOWN_SHELL: &str = "<unknown shell>"; @@ -50,7 +68,7 @@ fn get_pkg_branch_tag() -> &'static str { 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() { "powershell" | "pwsh" => "pwsh", "fish" => "fish", @@ -60,7 +78,7 @@ fn make_github_issue_link(environment: Environment) -> String { _ => "bash", }; - let body = urlencoding::encode(&format!("#### Current Behavior + format!("#### Current Behavior <!-- A clear and concise description of the behavior. --> #### Expected Behavior @@ -109,13 +127,16 @@ fn make_github_issue_link(environment: Environment) -> String { build_rust_channel = shadow::BUILD_RUST_CHANNEL, build_time = shadow::BUILD_TIME, shell_syntax = shell_syntax, - )) - .replace("%20", "+"); + ) +} + +fn make_github_issue_link(body: &str) -> String { + let escaped = urlencoding::encode(body).replace("%20", "+"); format!( "https://github.com/starship/starship/issues/new?template={}&body={}", urlencoding::encode("Bug_report.md"), - body + escaped ) .chars() .take(GITHUB_CHAR_LIMIT) @@ -259,7 +280,8 @@ mod tests { 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("Linux")); |