(724dc03) Add -o <owner> flag to comment subcommand

This commit is contained in:
2026-05-15 16:32:03 +02:00
parent 443586a583
commit dd5692d0a3
4 changed files with 58 additions and 3 deletions
+4
View File
@@ -77,5 +77,9 @@ pub enum Command {
/// Comment body (required)
body: String,
/// Owner
#[arg(short, long)]
owner: Option<String>,
},
}
+5 -2
View File
@@ -351,7 +351,7 @@ pub fn cmd_mv(ticket_id: &str, target_status: &str, force: bool, start: &Path) -
Ok(())
}
pub fn cmd_comment(ticket_id: &str, body: &str, start: &Path) -> Result<()> {
pub fn cmd_comment(ticket_id: &str, body: &str, owner: &Option<String>, start: &Path) -> Result<()> {
if body.is_empty() {
return Err(anyhow!("Comment body is required."));
}
@@ -371,7 +371,10 @@ pub fn cmd_comment(ticket_id: &str, body: &str, start: &Path) -> Result<()> {
let filename = format!("{}.md", timestamp);
let filepath = comments_dir.join(&filename);
let author = get_git_user().unwrap_or_else(|| "unknown".to_string());
let author = match owner {
Some(o) => o.clone(),
None => get_git_user().unwrap_or_else(|| "unknown".to_string()),
};
let comment_content = format!(
"**Comment**\n\
+1 -1
View File
@@ -47,6 +47,6 @@ fn main() -> Result<()> {
status,
force,
} => cmd_mv(&ticket, &status, force, &start),
Command::Comment { ticket, body } => cmd_comment(&ticket, &body, &start),
Command::Comment { ticket, body, owner } => cmd_comment(&ticket, &body, &owner, &start),
}
}
+48
View File
@@ -164,3 +164,51 @@ fn comment_creates_comments_directory() {
assert!(comments_dir.exists());
}
#[test]
fn comment_uses_owner_flag_when_provided() {
let temp = TempDir::new().unwrap();
let worklane = setup_worklane(&temp);
let uuid = create_ticket(&worklane, "backlog", "Owner Test");
let mut cmd = Command::cargo_bin(BIN_NAME).unwrap();
cmd.current_dir(&temp.path())
.arg("comment")
.args([&uuid, "Test comment with owner"])
.arg("-o")
.arg("TestUser")
.assert()
.success();
let comments_dir = worklane.join("comments").join(&uuid);
let files: Vec<_> = fs::read_dir(&comments_dir)
.unwrap()
.filter_map(|e| e.ok())
.collect();
let content = fs::read_to_string(files[0].path()).unwrap();
assert!(content.contains("**Author**: TestUser"));
}
#[test]
fn comment_falls_back_to_git_user_when_owner_omitted() {
let temp = TempDir::new().unwrap();
let worklane = setup_worklane(&temp);
let uuid = create_ticket(&worklane, "done", "Fallback Test");
let mut cmd = Command::cargo_bin(BIN_NAME).unwrap();
cmd.current_dir(&temp.path())
.arg("comment")
.args([&uuid, "Test comment fallback"])
.assert()
.success();
let comments_dir = worklane.join("comments").join(&uuid);
let files: Vec<_> = fs::read_dir(&comments_dir)
.unwrap()
.filter_map(|e| e.ok())
.collect();
let content = fs::read_to_string(files[0].path()).unwrap();
assert!(content.contains("**Author**"));
}