add author to Comment

This commit is contained in:
Sebastian Kuzminsky 2025-07-08 14:08:21 -06:00
parent 304b6b0d17
commit 7acd94f7c0
5 changed files with 30 additions and 1 deletions

View file

@ -115,6 +115,7 @@ fn handle_command(args: &Args, issues_dir: &std::path::Path) -> anyhow::Result<(
for comment in &issue.comments {
println!("");
println!("comment: {}", comment.uuid);
println!("author: {}", comment.author);
println!("timestamp: {}", comment.timestamp);
println!("{}", comment.description);
}

View file

@ -3,6 +3,7 @@ use std::io::Write;
#[derive(Debug, PartialEq)]
pub struct Comment {
pub uuid: String,
pub author: String,
pub timestamp: chrono::DateTime<chrono::Local>,
pub description: String,
@ -45,11 +46,13 @@ impl Comment {
return Err(CommentError::CommentParseError);
}
let author = crate::git::git_log_oldest_author(comment_dir)?;
let timestamp = crate::git::git_log_oldest_timestamp(comment_dir)?;
let dir = std::path::PathBuf::from(comment_dir);
Ok(Self {
uuid: String::from(dir.file_name().unwrap().to_string_lossy()),
author,
timestamp,
description: description.unwrap(),
dir: std::path::PathBuf::from(comment_dir),
@ -102,6 +105,7 @@ mod tests {
let comment = Comment::new_from_dir(comment_dir).unwrap();
let expected = Comment {
uuid: String::from("9055dac36045fe36545bed7ae7b49347"),
author: String::from("Sebastian Kuzminsky <seb@highlab.com>"),
timestamp: chrono::DateTime::parse_from_rfc3339("2025-07-07T15:26:26-06:00")
.unwrap()
.with_timezone(&chrono::Local),

View file

@ -210,6 +210,28 @@ pub fn git_log_oldest_timestamp(
Ok(timestamp)
}
pub fn git_log_oldest_author(path: &std::path::Path) -> Result<String, GitError> {
let mut git_dir = std::path::PathBuf::from(path);
git_dir.pop();
let result = std::process::Command::new("git")
.args([
"log",
"--pretty=format:%an <%ae>",
"--",
&path.file_name().unwrap().to_string_lossy(),
])
.current_dir(&git_dir)
.output()?;
if !result.status.success() {
println!("stdout: {}", std::str::from_utf8(&result.stdout).unwrap());
println!("stderr: {}", std::str::from_utf8(&result.stderr).unwrap());
return Err(GitError::Oops);
}
let author_str = std::str::from_utf8(&result.stdout).unwrap();
let author_last = author_str.split("\n").last().unwrap();
Ok(String::from(author_last))
}
pub fn create_orphan_branch(branch: &str) -> Result<(), GitError> {
{
let tmp_worktree = tempfile::tempdir().unwrap();

View file

@ -156,6 +156,7 @@ impl Issue {
Ok(crate::comment::Comment {
uuid,
author: String::from("Sebastian Kuzminsky <seb@highlab.com>"),
timestamp: chrono::Local::now(),
description: String::from(""), // FIXME
dir,

View file

@ -152,8 +152,9 @@ mod tests {
expected_comments.push(
crate::comment::Comment {
uuid: comment_uuid,
description: String::from("This is a comment on issue dd79c8cfb8beeacd0460429944b4ecbe95a31561\n\nIt has multiple lines\n"),
author: String::from("Sebastian Kuzminsky <seb@highlab.com>"),
timestamp: chrono::DateTime::parse_from_rfc3339("2025-07-07T15:26:26-06:00").unwrap().with_timezone(&chrono::Local),
description: String::from("This is a comment on issue dd79c8cfb8beeacd0460429944b4ecbe95a31561\n\nIt has multiple lines\n"),
dir: std::path::PathBuf::from(comment_dir),
}
);