diff options
author | Jon Grythe Stødle <jonstodle@outlook.com> | 2020-01-16 05:47:56 +0100 |
---|---|---|
committer | Matan Kushner <hello@matchai.me> | 2020-01-15 23:47:56 -0500 |
commit | 313a03e2b7afae34d83ec677d83d766eb3ffceeb (patch) | |
tree | 363553a98eebab0b004028c126f3bf5200e95e44 | |
parent | 0fe90bf0188f94be8334ff9030bcb9ed42e3329b (diff) |
fix(bug-report): Fix status code 414 when generated bug report is too long (#750)
-rw-r--r-- | src/bug_report.rs | 41 |
1 files changed, 22 insertions, 19 deletions
diff --git a/src/bug_report.rs b/src/bug_report.rs index e78644ac9..8e53c4e14 100644 --- a/src/bug_report.rs +++ b/src/bug_report.rs @@ -40,6 +40,7 @@ const UNKNOWN_SHELL: &str = "<unknown shell>"; const UNKNOWN_TERMINAL: &str = "<unknown terminal>"; const UNKNOWN_VERSION: &str = "<unknown version>"; const UNKNOWN_CONFIG: &str = "<unknown config>"; +const GITHUB_CHAR_LIMIT: usize = 8100; // Magic number accepted by Github struct Environment { os_type: os_info::Type, @@ -50,18 +51,7 @@ struct Environment { } fn make_github_issue_link(starship_version: &str, environment: Environment) -> String { - let template_filename = urlencoding::encode("Bug_report.md"); - - let body = urlencoding::encode(&format!("<!-- -───────────────────────────────────────────── - This issue has been pre-populated with your system's configuration - ♥ Thank you for submitting a bug report ♥ -───────────────────────────────────────────── ---> - -## Bug Report - -#### Current Behavior + let body = urlencoding::encode(&format!("#### Current Behavior <!-- A clear and concise description of the behavior. --> #### Expected Behavior @@ -99,12 +89,17 @@ fn make_github_issue_link(starship_version: &str, environment: Environment) -> S os_version = environment.os_version, shell_config = environment.shell_info.config, starship_config = environment.starship_config, - )); + )) + .replace("%20", "+"); format!( "https://github.com/starship/starship/issues/new?template={}&body={}", - template_filename, body + urlencoding::encode("Bug_report.md"), + body ) + .chars() + .take(GITHUB_CHAR_LIMIT) + .collect() } #[derive(Debug)] @@ -184,8 +179,16 @@ fn get_config_path(shell: &str) -> Option<PathBuf> { } fn get_starship_config() -> String { - dirs::home_dir() - .and_then(|home_dir| fs::read_to_string(home_dir.join(".config/starship.toml")).ok()) + std::env::var("STARSHIP_CONFIG") + .map(PathBuf::from) + .ok() + .or_else(|| { + dirs::home_dir().map(|mut home_dir| { + home_dir.push(".config/starship.toml"); + home_dir + }) + }) + .and_then(|config_path| fs::read_to_string(config_path).ok()) .unwrap_or_else(|| UNKNOWN_CONFIG.to_string()) } @@ -196,7 +199,7 @@ mod tests { use std::env; #[test] - fn test_make_github_issue_link() { + fn test_make_github_link() { let starship_version = "0.1.2"; let environment = Environment { os_type: os_info::Type::Linux, @@ -220,8 +223,8 @@ mod tests { assert!(link.contains("1.2.3")); assert!(link.contains("test_shell")); assert!(link.contains("2.3.4")); - assert!(link.contains("No%20config")); - assert!(link.contains("No%20Starship%20config")); + assert!(link.contains("No+config")); + assert!(link.contains("No+Starship+config")); } #[test] |