Compare commits

...

2 commits

Author SHA1 Message Date
2d759ca4ab fixup timestamp 2025-07-07 23:57:33 -06:00
19a99c6b0e WIP 2025-07-07 23:45:03 -06:00
6 changed files with 38 additions and 3 deletions

View file

@ -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"

View file

@ -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);
}
}

View file

@ -3,6 +3,7 @@ use std::io::Write;
#[derive(Debug, PartialEq)]
pub struct Comment {
pub description: String,
pub timestamp: chrono::DateTime<chrono::Local>,
/// 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-07T15:26:26-06:00").unwrap().with_timezone(&chrono::Local),
dir: std::path::PathBuf::from(comment_dir),
};
assert_eq!(comment, expected);

View file

@ -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,33 @@ pub fn git_commit_file(file: &std::path::Path) -> Result<(), GitError> {
Ok(())
}
pub fn git_log_oldest_timestamp(
path: &std::path::Path,
) -> Result<chrono::DateTime<chrono::Local>, GitError> {
let mut git_dir = std::path::PathBuf::from(path);
git_dir.pop();
let result = std::process::Command::new("git")
.args([
"log",
"--pretty=format:%at",
&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 timestamp_str = std::str::from_utf8(&result.stdout).unwrap();
let timestamp_i64 = timestamp_str.parse::<i64>()?;
let timestamp: chrono::DateTime<chrono::Local> =
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();

View file

@ -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,
})
}

View file

@ -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-07T15:26:26-06:00").unwrap().with_timezone(&chrono::Local),
dir: std::path::PathBuf::from(comment_dir),
}
);