(1240895) Add colour to disambiguation
This commit is contained in:
+17
-8
@@ -72,7 +72,7 @@ pub fn get_git_user() -> Option<String> {
|
|||||||
}
|
}
|
||||||
pub fn resolve_ticket(search: &str, worklane_dir: &Path) -> Result<(String, String, String)> {
|
pub fn resolve_ticket(search: &str, worklane_dir: &Path) -> Result<(String, String, String)> {
|
||||||
let statuses = status_dirs();
|
let statuses = status_dirs();
|
||||||
let mut matches: Vec<(String, String, String)> = Vec::new();
|
let mut matches: Vec<(String, String, String, String)> = Vec::new();
|
||||||
|
|
||||||
for status in &statuses {
|
for status in &statuses {
|
||||||
let status_path = worklane_dir.join(status);
|
let status_path = worklane_dir.join(status);
|
||||||
@@ -99,18 +99,19 @@ pub fn resolve_ticket(search: &str, worklane_dir: &Path) -> Result<(String, Stri
|
|||||||
.file_stem()
|
.file_stem()
|
||||||
.map(|s| s.to_string_lossy().to_string())
|
.map(|s| s.to_string_lossy().to_string())
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
let id = filename.split('_').next().unwrap_or("");
|
let short_id = filename.split('_').next().unwrap_or("");
|
||||||
|
|
||||||
let search_lower = search.to_lowercase();
|
let search_lower = search.to_lowercase();
|
||||||
let title_lower = title.to_lowercase();
|
let title_lower = title.to_lowercase();
|
||||||
let filename_lower = filename.to_lowercase();
|
let filename_lower = filename.to_lowercase();
|
||||||
|
|
||||||
let id_match = id.to_lowercase().starts_with(&search_lower) && id.len() >= 8;
|
let id_match =
|
||||||
|
short_id.to_lowercase().starts_with(&search_lower) && short_id.len() >= 8;
|
||||||
let title_match = title_lower.contains(&search_lower);
|
let title_match = title_lower.contains(&search_lower);
|
||||||
let filename_match = filename_lower.contains(&search_lower);
|
let filename_match = filename_lower.contains(&search_lower);
|
||||||
|
|
||||||
if id_match || title_match || filename_match {
|
if id_match || title_match || filename_match {
|
||||||
matches.push((status.to_string(), title, content));
|
matches.push((status.to_string(), title, content, short_id.to_string()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -121,14 +122,22 @@ pub fn resolve_ticket(search: &str, worklane_dir: &Path) -> Result<(String, Stri
|
|||||||
|
|
||||||
if matches.len() > 1 {
|
if matches.len() > 1 {
|
||||||
println!("Multiple tickets found matching '{}':", search);
|
println!("Multiple tickets found matching '{}':", search);
|
||||||
for (i, (status, title, _)) in matches.iter().enumerate() {
|
for (i, (status, title, _, short_id)) in matches.iter().enumerate() {
|
||||||
println!(" {}. {} ({})", i + 1, title, status);
|
let display_id = &short_id[..7];
|
||||||
|
println!(
|
||||||
|
" {}. ({}) {} [{}]",
|
||||||
|
i + 1,
|
||||||
|
color_text(display_id, "red"),
|
||||||
|
title,
|
||||||
|
color_text(status, "orange"),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
println!("\nTry a more specific search term.");
|
println!("\nUse the displayed ID or a more specific search term to select.");
|
||||||
std::process::exit(1);
|
std::process::exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(matches.remove(0))
|
let (status, title, content, _short_id) = matches.remove(0);
|
||||||
|
Ok((status, title, content))
|
||||||
}
|
}
|
||||||
pub fn format_comments(comments: &[(String, String, String, String)]) -> String {
|
pub fn format_comments(comments: &[(String, String, String, String)]) -> String {
|
||||||
if comments.is_empty() {
|
if comments.is_empty() {
|
||||||
|
|||||||
@@ -260,6 +260,9 @@ fn show_asks_for_disambiguation_when_multiple_matches() {
|
|||||||
assert!(stdout.contains("Multiple tickets found"));
|
assert!(stdout.contains("Multiple tickets found"));
|
||||||
assert!(stdout.contains("Test Ticket A"));
|
assert!(stdout.contains("Test Ticket A"));
|
||||||
assert!(stdout.contains("Test Ticket B"));
|
assert!(stdout.contains("Test Ticket B"));
|
||||||
|
assert!(stdout.contains("abc123d"));
|
||||||
|
assert!(stdout.contains("fedcba0"));
|
||||||
|
assert!(stdout.contains("Use the displayed ID"));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
Reference in New Issue
Block a user