(339c65a) Add comment command
This commit is contained in:
+43
@@ -535,6 +535,46 @@ fn cmd_mv(ticket_id: &str, target_status: &str, force: bool, start: &Path) -> Re
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn cmd_comment(ticket_id: &str, body: &str, start: &Path) -> Result<()> {
|
||||
if body.is_empty() {
|
||||
return Err(anyhow!("Comment body is required."));
|
||||
}
|
||||
|
||||
let worklane_dir = find_worklane_dir(start)?;
|
||||
let (_status, title, content) = resolve_ticket(ticket_id, &worklane_dir)?;
|
||||
let ticket_uuid = parse_ticket_field(&content, "ID");
|
||||
|
||||
if ticket_uuid == "_Not set_" {
|
||||
return Err(anyhow!("Could not determine ticket ID."));
|
||||
}
|
||||
|
||||
let comments_dir = worklane_dir.join("comments").join(&ticket_uuid);
|
||||
fs::create_dir_all(&comments_dir)?;
|
||||
|
||||
let timestamp = Local::now().format("%Y%m%d_%H%M%S");
|
||||
let filename = format!("{}.md", timestamp);
|
||||
let filepath = comments_dir.join(&filename);
|
||||
|
||||
let author = get_git_user().unwrap_or_else(|| "unknown".to_string());
|
||||
|
||||
let comment_content = format!(
|
||||
"**Comment**\n\
|
||||
{}\n\
|
||||
\n\
|
||||
**Author**: {}\n\
|
||||
**Time**: {}\n\
|
||||
",
|
||||
body,
|
||||
author,
|
||||
Local::now().format("%Y-%m-%d %H:%M:%S")
|
||||
);
|
||||
|
||||
fs::write(&filepath, comment_content)?;
|
||||
|
||||
println!("Comment added to '{}' ({})", title, filename);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn content_trim_colored(content: &str) -> String {
|
||||
let lines: Vec<&str> = content.trim().lines().collect();
|
||||
let mut result = String::new();
|
||||
@@ -732,5 +772,8 @@ fn main() -> Result<()> {
|
||||
Command::Mv { ticket, status, force } => {
|
||||
cmd_mv(&ticket, &status, force, &start)
|
||||
}
|
||||
Command::Comment { ticket, body } => {
|
||||
cmd_comment(&ticket, &body, &start)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user