give Comment a timestamp, display in chronological order

This commit makes a couple of changes:

- `ent show ISSUE` now displays the Issue's Comments in chronological
  order

- the Comment struct now includes a timestamp, which is the Author Time
  of the oldest commit that touches the comment's directory

- the Issue struct now stores its Comments in a sorted Vec, not in
  a HashMap

- The Comment's uuid moved into the Comment struct itself, instead of
  being the key in the Issue's HashMap of Comments
This commit is contained in:
Sebastian Kuzminsky 2025-07-07 23:45:03 -06:00
parent 431c67d43d
commit be362517fb
6 changed files with 65 additions and 23 deletions

View file

@ -2,6 +2,8 @@ use std::io::Write;
#[derive(Debug, PartialEq)]
pub struct Comment {
pub uuid: String,
pub timestamp: chrono::DateTime<chrono::Local>,
pub description: String,
/// This is the directory that the comment lives in. Only used
@ -39,12 +41,16 @@ impl Comment {
}
}
}
if description == None {
return Err(CommentError::CommentParseError);
}
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()),
timestamp,
description: description.unwrap(),
dir: std::path::PathBuf::from(comment_dir),
})
@ -95,8 +101,11 @@ mod tests {
std::path::Path::new("test/0001/dd79c8cfb8beeacd0460429944b4ecbe95a31561/comments/9055dac36045fe36545bed7ae7b49347");
let comment = Comment::new_from_dir(comment_dir).unwrap();
let expected = Comment {
uuid: String::from("9055dac36045fe36545bed7ae7b49347"),
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),
};
assert_eq!(comment, expected);