mirror of
https://github.com/starship/starship.git
synced 2025-06-27 05:12:15 +02:00
fix(bug-report): Fix status code 414 when generated bug report is too long (#750)
This commit is contained in:
parent
0fe90bf018
commit
313a03e2b7
@ -40,6 +40,7 @@ const UNKNOWN_SHELL: &str = "<unknown shell>";
|
|||||||
const UNKNOWN_TERMINAL: &str = "<unknown terminal>";
|
const UNKNOWN_TERMINAL: &str = "<unknown terminal>";
|
||||||
const UNKNOWN_VERSION: &str = "<unknown version>";
|
const UNKNOWN_VERSION: &str = "<unknown version>";
|
||||||
const UNKNOWN_CONFIG: &str = "<unknown config>";
|
const UNKNOWN_CONFIG: &str = "<unknown config>";
|
||||||
|
const GITHUB_CHAR_LIMIT: usize = 8100; // Magic number accepted by Github
|
||||||
|
|
||||||
struct Environment {
|
struct Environment {
|
||||||
os_type: os_info::Type,
|
os_type: os_info::Type,
|
||||||
@ -50,18 +51,7 @@ struct Environment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn make_github_issue_link(starship_version: &str, environment: Environment) -> String {
|
fn make_github_issue_link(starship_version: &str, environment: Environment) -> String {
|
||||||
let template_filename = urlencoding::encode("Bug_report.md");
|
let body = urlencoding::encode(&format!("#### Current Behavior
|
||||||
|
|
||||||
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
|
|
||||||
<!-- A clear and concise description of the behavior. -->
|
<!-- A clear and concise description of the behavior. -->
|
||||||
|
|
||||||
#### Expected Behavior
|
#### Expected Behavior
|
||||||
@ -99,12 +89,17 @@ fn make_github_issue_link(starship_version: &str, environment: Environment) -> S
|
|||||||
os_version = environment.os_version,
|
os_version = environment.os_version,
|
||||||
shell_config = environment.shell_info.config,
|
shell_config = environment.shell_info.config,
|
||||||
starship_config = environment.starship_config,
|
starship_config = environment.starship_config,
|
||||||
));
|
))
|
||||||
|
.replace("%20", "+");
|
||||||
|
|
||||||
format!(
|
format!(
|
||||||
"https://github.com/starship/starship/issues/new?template={}&body={}",
|
"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)]
|
#[derive(Debug)]
|
||||||
@ -184,8 +179,16 @@ fn get_config_path(shell: &str) -> Option<PathBuf> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn get_starship_config() -> String {
|
fn get_starship_config() -> String {
|
||||||
dirs::home_dir()
|
std::env::var("STARSHIP_CONFIG")
|
||||||
.and_then(|home_dir| fs::read_to_string(home_dir.join(".config/starship.toml")).ok())
|
.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())
|
.unwrap_or_else(|| UNKNOWN_CONFIG.to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -196,7 +199,7 @@ mod tests {
|
|||||||
use std::env;
|
use std::env;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_make_github_issue_link() {
|
fn test_make_github_link() {
|
||||||
let starship_version = "0.1.2";
|
let starship_version = "0.1.2";
|
||||||
let environment = Environment {
|
let environment = Environment {
|
||||||
os_type: os_info::Type::Linux,
|
os_type: os_info::Type::Linux,
|
||||||
@ -220,8 +223,8 @@ mod tests {
|
|||||||
assert!(link.contains("1.2.3"));
|
assert!(link.contains("1.2.3"));
|
||||||
assert!(link.contains("test_shell"));
|
assert!(link.contains("test_shell"));
|
||||||
assert!(link.contains("2.3.4"));
|
assert!(link.contains("2.3.4"));
|
||||||
assert!(link.contains("No%20config"));
|
assert!(link.contains("No+config"));
|
||||||
assert!(link.contains("No%20Starship%20config"));
|
assert!(link.contains("No+Starship+config"));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user