WIP
This commit is contained in:
parent
4d6e18a9f4
commit
19a99c6b0e
6 changed files with 37 additions and 3 deletions
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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-01T15:26:26").unwrap().with_timezone(&chrono::Local),
|
||||
dir: std::path::PathBuf::from(comment_dir),
|
||||
};
|
||||
assert_eq!(comment, expected);
|
||||
|
|
|
|||
28
src/git.rs
28
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<chrono::DateTime<chrono::Local>, 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::<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();
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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),
|
||||
}
|
||||
);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue