From 19a99c6b0e041d1c0cb1ebfd0c13e8c0e11847ef Mon Sep 17 00:00:00 2001 From: Sebastian Kuzminsky Date: Mon, 7 Jul 2025 23:45:03 -0600 Subject: [PATCH] WIP --- Cargo.toml | 1 + src/bin/ent/main.rs | 1 + src/comment.rs | 7 +++++-- src/git.rs | 28 ++++++++++++++++++++++++++++ src/issue.rs | 2 +- src/issues.rs | 1 + 6 files changed, 37 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index fccb9c9..af271d7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,6 +9,7 @@ log = ["dep:log", "dep:simple_logger"] [dependencies] anyhow = "1.0.95" +chrono = "0.4.41" clap = { version = "4.5.26", features = ["derive"] } log = { version = "0.4.27", optional = true } rand = "0.9.1" diff --git a/src/bin/ent/main.rs b/src/bin/ent/main.rs index 1c9ddaa..9f8b6da 100644 --- a/src/bin/ent/main.rs +++ b/src/bin/ent/main.rs @@ -99,6 +99,7 @@ fn handle_command(args: &Args, issues_dir: &std::path::Path) -> anyhow::Result<( for (uuid, comment) in issue.comments.iter() { println!(""); println!("comment: {}", uuid); + println!("timestamp: {}", comment.timestamp); println!("{}", comment.description); } } diff --git a/src/comment.rs b/src/comment.rs index ab2ced9..fd83b5c 100644 --- a/src/comment.rs +++ b/src/comment.rs @@ -3,6 +3,7 @@ use std::io::Write; #[derive(Debug, PartialEq)] pub struct Comment { pub description: String, + pub timestamp: chrono::DateTime, /// This is the directory that the comment lives in. Only used /// internally by the entomologist library. @@ -39,13 +40,15 @@ impl Comment { } } } - if description == None { return Err(CommentError::CommentParseError); } + let timestamp = crate::git::git_log_oldest_timestamp(comment_dir)?; + Ok(Self { description: description.unwrap(), + timestamp, dir: std::path::PathBuf::from(comment_dir), }) } @@ -96,7 +99,7 @@ mod tests { let comment = Comment::new_from_dir(comment_dir).unwrap(); let expected = Comment { description: String::from("This is a comment on issue dd79c8cfb8beeacd0460429944b4ecbe95a31561\n\nIt has multiple lines\n"), - + timestamp: chrono::DateTime::parse_from_rfc3339("2025-07-01T15:26:26").unwrap().with_timezone(&chrono::Local), dir: std::path::PathBuf::from(comment_dir), }; assert_eq!(comment, expected); diff --git a/src/git.rs b/src/git.rs index caa5e4b..9fa9ffe 100644 --- a/src/git.rs +++ b/src/git.rs @@ -4,6 +4,8 @@ use std::io::Write; pub enum GitError { #[error(transparent)] StdIoError(#[from] std::io::Error), + #[error(transparent)] + ParseIntError(#[from] std::num::ParseIntError), #[error("Oops, something went wrong")] Oops, } @@ -124,6 +126,32 @@ pub fn git_commit_file(file: &std::path::Path) -> Result<(), GitError> { Ok(()) } +pub fn git_log_oldest_timestamp( + path: &std::path::Path, +) -> Result, GitError> { + let result = std::process::Command::new("git") + .args(["log", "--pretty=format:%at", &path.to_string_lossy()]) + .output()?; + println!("git logging path is {:?}", path); + 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 timestamp_str = std::str::from_utf8(&result.stdout).unwrap(); + println!( + "timestamp of '{}': {}", + path.file_name().unwrap().to_string_lossy(), + timestamp_str + ); + let timestamp_i64 = timestamp_str.parse::()?; + let timestamp: chrono::DateTime = + chrono::DateTime::from_timestamp(timestamp_i64, 0) + .unwrap() + .with_timezone(&chrono::Local); + Ok(timestamp) +} + pub fn create_orphan_branch(branch: &str) -> Result<(), GitError> { { let tmp_worktree = tempfile::tempdir().unwrap(); diff --git a/src/issue.rs b/src/issue.rs index c762c82..f8adcde 100644 --- a/src/issue.rs +++ b/src/issue.rs @@ -75,7 +75,6 @@ impl fmt::Display for State { State::InProgress => "inprogress", State::Done => "done", State::WontDo => "wontdo", - }; write!(f, "{fmt_str}") } @@ -155,6 +154,7 @@ impl Issue { Ok(crate::comment::Comment { description: String::from(""), // FIXME + timestamp: chrono::Local::now(), dir, }) } diff --git a/src/issues.rs b/src/issues.rs index 28df2e9..29162c6 100644 --- a/src/issues.rs +++ b/src/issues.rs @@ -154,6 +154,7 @@ mod tests { String::from(&comment_uuid), crate::comment::Comment { description: String::from("This is a comment on issue dd79c8cfb8beeacd0460429944b4ecbe95a31561\n\nIt has multiple lines\n"), + timestamp: chrono::DateTime::parse_from_rfc3339("2025-07-01T15:26:26").unwrap().with_timezone(&chrono::Local), dir: std::path::PathBuf::from(comment_dir), } );