refactor ent comment

Instead of a two-step process handled by the application
(`Issue::new_comment()` and `Comment::set_description()` or
`Comment::edit_description()`), make a simpler-to-use single-step
`Issue::add_comment()`.

Move the implementation details from Issue to Comment.

Better log message when adding a comment.
This commit is contained in:
Sebastian Kuzminsky 2025-07-11 11:48:39 -06:00
parent 1c8d994fd9
commit d642004ee0
3 changed files with 111 additions and 60 deletions

View file

@ -161,25 +161,13 @@ impl Issue {
Ok(())
}
pub fn new_comment(&mut self) -> Result<crate::comment::Comment, IssueError> {
let mut dir = std::path::PathBuf::from(&self.dir);
dir.push("comments");
if !dir.exists() {
std::fs::create_dir(&dir)?;
}
let rnd: u128 = rand::random();
let uuid = format!("{:032x}", rnd);
dir.push(&uuid);
std::fs::create_dir(&dir)?;
Ok(crate::comment::Comment {
uuid,
author: String::from("Sebastian Kuzminsky <seb@highlab.com>"),
timestamp: chrono::Local::now(),
description: String::from(""), // FIXME
dir,
})
/// Add a new Comment to the Issue. Commits.
pub fn add_comment(
&mut self,
description: &Option<String>,
) -> Result<crate::comment::Comment, IssueError> {
let comment = crate::comment::Comment::new(self, description)?;
Ok(comment)
}
/// Create a new Issue in an Issues database specified by a directory.