(a0dc5e3) Display comments under worklane show

This commit is contained in:
2026-05-15 12:00:22 +02:00
parent bc3ee0c53b
commit cd19e4e6cf
3 changed files with 103 additions and 14 deletions
+95 -10
View File
@@ -423,13 +423,95 @@ fn resolve_ticket(search: &str, worklane_dir: &Path) -> Result<(String, String,
Ok(matches.remove(0))
}
fn read_comments(comments_dir: &Path) -> Result<Vec<(String, String, String, String)>> {
if !comments_dir.exists() {
return Ok(vec![]);
}
let mut comments: Vec<(String, String, String, String)> = Vec::new();
for entry in fs::read_dir(comments_dir)? {
let entry = entry?;
let path = entry.path();
if path.extension().map_or(false, |e| e == "md") {
let content = fs::read_to_string(&path)?;
let filename = path
.file_stem()
.map(|s| s.to_string_lossy().to_string())
.unwrap_or_default();
let author = content
.lines()
.find(|l| l.starts_with("**Author**"))
.and_then(|l| l.splitn(2, "**Author**:").nth(1))
.map(|s| s.trim().to_string())
.unwrap_or_else(|| "unknown".to_string());
let time = content
.lines()
.find(|l| l.starts_with("**Time**"))
.and_then(|l| l.splitn(2, "**Time**:").nth(1))
.map(|s| s.trim().to_string())
.unwrap_or_else(|| "unknown".to_string());
let body = if let Some(after_comment) = content.strip_prefix("**Comment**\n") {
if let Some(end) = after_comment.find("\n\n**Author**") {
after_comment[..end].trim()
} else {
after_comment.trim()
}
} else {
""
};
comments.push((filename, author, time, body.to_string()));
}
}
comments.sort_by(|a, b| a.0.cmp(&b.0));
Ok(comments)
}
fn format_comments(comments: &[(String, String, String, String)]) -> String {
if comments.is_empty() {
return color_text("No comments yet.", "grey");
}
let mut result = String::new();
result.push_str("\n");
result.push_str(&color_text("COMMENTS", "orange"));
result.push_str(&format!("\n{}\n", "─".repeat(20)));
for (_filename, author, time, body) in comments {
result.push_str("\n");
result.push_str(&color_text(&format!("From {} ({})", author, time), "cyan"));
result.push_str("\n");
if !body.is_empty() {
result.push_str(&" ".to_string());
result.push_str(body);
}
result.push('\n');
}
result
}
fn cmd_show(search: &str, worklane_dir: &Path) -> Result<()> {
let (_status, title, content) = resolve_ticket(search, worklane_dir)?;
let ticket_uuid = parse_ticket_field(&content, "ID");
println!("{}", title);
println!("{}", "─".repeat(title.len()));
println!("\n{}", content_trim_colored(&content));
if ticket_uuid != "_Not set_" {
let comments_dir = worklane_dir.join("comments").join(&ticket_uuid);
let comments = read_comments(&comments_dir)?;
let formatted = format_comments(&comments);
println!("{}", formatted);
}
Ok(())
}
@@ -447,7 +529,7 @@ fn cmd_mv(ticket_id: &str, target_status: &str, force: bool, start: &Path) -> Re
let worklane_dir = find_worklane_dir(start)?;
let (current_status, title, _) = resolve_ticket(ticket_id, &worklane_dir)?;
let current_idx = forward_order
.iter()
.position(|&s| s == current_status)
@@ -505,7 +587,7 @@ fn cmd_mv(ticket_id: &str, target_status: &str, force: bool, start: &Path) -> Re
// Read and update the ticket content
let mut content = fs::read_to_string(current_path.join(&found_filename))?;
// Update Status in Metadata section
if let Some(start_pos) = content.find("- **Status**") {
// Skip "- " to find "**Status**"
@@ -530,8 +612,11 @@ fn cmd_mv(ticket_id: &str, target_status: &str, force: bool, start: &Path) -> Re
// Write back updated content
fs::write(target_path.join(&found_filename), content)?;
println!("Moved ticket '{}' from {} to {}", title, current_status, target_status);
println!(
"Moved ticket '{}' from {} to {}",
title, current_status, target_status
);
Ok(())
}
@@ -769,11 +854,11 @@ fn main() -> Result<()> {
let worklane_dir = find_worklane_dir(&start)?;
cmd_show(&id, &worklane_dir)
}
Command::Mv { ticket, status, force } => {
cmd_mv(&ticket, &status, force, &start)
}
Command::Comment { ticket, body } => {
cmd_comment(&ticket, &body, &start)
}
Command::Mv {
ticket,
status,
force,
} => cmd_mv(&ticket, &status, force, &start),
Command::Comment { ticket, body } => cmd_comment(&ticket, &body, &start),
}
}