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:
parent
5cfb7401db
commit
1fa3aae2c0
6 changed files with 65 additions and 23 deletions
21
src/issue.rs
21
src/issue.rs
|
|
@ -23,7 +23,7 @@ pub struct Issue {
|
|||
pub description: String,
|
||||
pub state: State,
|
||||
pub dependencies: Option<Vec<IssueHandle>>,
|
||||
pub comments: std::collections::HashMap<String, crate::comment::Comment>,
|
||||
pub comments: Vec<crate::comment::Comment>,
|
||||
|
||||
/// This is the directory that the issue lives in. Only used
|
||||
/// internally by the entomologist library.
|
||||
|
|
@ -85,7 +85,7 @@ impl Issue {
|
|||
let mut description: Option<String> = None;
|
||||
let mut state = State::New; // default state, if not specified in the issue
|
||||
let mut dependencies: Option<Vec<String>> = None;
|
||||
let mut comments = std::collections::HashMap::<String, crate::comment::Comment>::new();
|
||||
let mut comments = Vec::<crate::comment::Comment>::new();
|
||||
|
||||
for direntry in dir.read_dir()? {
|
||||
if let Ok(direntry) = direntry {
|
||||
|
|
@ -127,16 +127,16 @@ impl Issue {
|
|||
}
|
||||
|
||||
fn read_comments(
|
||||
comments: &mut std::collections::HashMap<String, crate::comment::Comment>,
|
||||
comments: &mut Vec<crate::comment::Comment>,
|
||||
dir: &std::path::Path,
|
||||
) -> Result<(), IssueError> {
|
||||
for direntry in dir.read_dir()? {
|
||||
if let Ok(direntry) = direntry {
|
||||
let uuid = direntry.file_name();
|
||||
let comment = crate::comment::Comment::new_from_dir(&direntry.path())?;
|
||||
comments.insert(String::from(uuid.to_string_lossy()), comment);
|
||||
comments.push(comment);
|
||||
}
|
||||
}
|
||||
comments.sort_by(|a, b| a.timestamp.cmp(&b.timestamp));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
@ -148,10 +148,13 @@ impl Issue {
|
|||
}
|
||||
|
||||
let rnd: u128 = rand::random();
|
||||
dir.push(&format!("{:032x}", rnd));
|
||||
let uuid = format!("{:032x}", rnd);
|
||||
dir.push(&uuid);
|
||||
std::fs::create_dir(&dir)?;
|
||||
|
||||
Ok(crate::comment::Comment {
|
||||
uuid,
|
||||
timestamp: chrono::Local::now(),
|
||||
description: String::from(""), // FIXME
|
||||
dir,
|
||||
})
|
||||
|
|
@ -166,7 +169,7 @@ impl Issue {
|
|||
description: String::from(""), // FIXME: kind of bogus to use the empty string as None
|
||||
state: State::New,
|
||||
dependencies: None,
|
||||
comments: std::collections::HashMap::<String, crate::comment::Comment>::new(),
|
||||
comments: Vec::<crate::comment::Comment>::new(),
|
||||
dir: issue_dir,
|
||||
})
|
||||
}
|
||||
|
|
@ -242,7 +245,7 @@ mod tests {
|
|||
description: String::from("this is the title of my issue\n\nThis is the description of my issue.\nIt is multiple lines.\n* Arbitrary contents\n* But let's use markdown by convention\n"),
|
||||
state: State::New,
|
||||
dependencies: None,
|
||||
comments: std::collections::HashMap::<String, crate::comment::Comment>::new(),
|
||||
comments: Vec::<crate::comment::Comment>::new(),
|
||||
dir: std::path::PathBuf::from(issue_dir),
|
||||
};
|
||||
assert_eq!(issue, expected);
|
||||
|
|
@ -256,7 +259,7 @@ mod tests {
|
|||
description: String::from("minimal"),
|
||||
state: State::InProgress,
|
||||
dependencies: None,
|
||||
comments: std::collections::HashMap::<String, crate::comment::Comment>::new(),
|
||||
comments: Vec::<crate::comment::Comment>::new(),
|
||||
dir: std::path::PathBuf::from(issue_dir),
|
||||
};
|
||||
assert_eq!(issue, expected);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue