diff --git a/src/bin/ent/main.rs b/src/bin/ent/main.rs index 1c9ddaa..9c31c60 100644 --- a/src/bin/ent/main.rs +++ b/src/bin/ent/main.rs @@ -39,12 +39,6 @@ enum Commands { issue_id: String, new_state: Option, }, - - /// Create a new comment on an issue. - Comment { - issue_id: String, - description: Option, - }, } fn handle_command(args: &Args, issues_dir: &std::path::Path) -> anyhow::Result<()> { @@ -96,11 +90,6 @@ fn handle_command(args: &Args, issues_dir: &std::path::Path) -> anyhow::Result<( } println!(""); println!("{}", issue.description); - for (uuid, comment) in issue.comments.iter() { - println!(""); - println!("comment: {}", uuid); - println!("{}", comment.description); - } } None => { return Err(anyhow::anyhow!("issue {} not found", issue_id)); @@ -134,26 +123,6 @@ fn handle_command(args: &Args, issues_dir: &std::path::Path) -> anyhow::Result<( } } } - - Commands::Comment { - issue_id, - description, - } => { - let mut issues = - entomologist::issues::Issues::new_from_dir(std::path::Path::new(issues_dir))?; - let Some(issue) = issues.get_mut_issue(issue_id) else { - return Err(anyhow::anyhow!("issue {} not found", issue_id)); - }; - let mut comment = issue.new_comment()?; - match description { - Some(description) => { - comment.set_description(description)?; - } - None => { - comment.edit_description()?; - } - } - } } Ok(()) diff --git a/src/comment.rs b/src/comment.rs deleted file mode 100644 index ab2ced9..0000000 --- a/src/comment.rs +++ /dev/null @@ -1,104 +0,0 @@ -use std::io::Write; - -#[derive(Debug, PartialEq)] -pub struct Comment { - pub description: String, - - /// This is the directory that the comment lives in. Only used - /// internally by the entomologist library. - pub dir: std::path::PathBuf, -} - -#[derive(Debug, thiserror::Error)] -pub enum CommentError { - #[error(transparent)] - StdIoError(#[from] std::io::Error), - #[error("Failed to parse comment")] - CommentParseError, - #[error("Failed to run git")] - GitError(#[from] crate::git::GitError), - #[error("Failed to run editor")] - EditorError, -} - -impl Comment { - pub fn new_from_dir(comment_dir: &std::path::Path) -> Result { - let mut description: Option = None; - - for direntry in comment_dir.read_dir()? { - if let Ok(direntry) = direntry { - let file_name = direntry.file_name(); - if file_name == "description" { - description = Some(std::fs::read_to_string(direntry.path())?); - } else { - #[cfg(feature = "log")] - debug!( - "ignoring unknown file in comment directory: {:?}", - file_name - ); - } - } - } - - if description == None { - return Err(CommentError::CommentParseError); - } - - Ok(Self { - description: description.unwrap(), - dir: std::path::PathBuf::from(comment_dir), - }) - } - - pub fn set_description(&mut self, description: &str) -> Result<(), CommentError> { - self.description = String::from(description); - let mut description_filename = std::path::PathBuf::from(&self.dir); - description_filename.push("description"); - let mut description_file = std::fs::File::create(&description_filename)?; - write!(description_file, "{}", description)?; - crate::git::git_commit_file(&description_filename)?; - Ok(()) - } - - pub fn read_description(&mut self) -> Result<(), CommentError> { - let mut description_filename = std::path::PathBuf::from(&self.dir); - description_filename.push("description"); - self.description = std::fs::read_to_string(description_filename)?; - Ok(()) - } - - pub fn edit_description(&mut self) -> Result<(), CommentError> { - let mut description_filename = std::path::PathBuf::from(&self.dir); - description_filename.push("description"); - let result = std::process::Command::new("vi") - .arg(&description_filename.as_mut_os_str()) - .spawn()? - .wait_with_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(CommentError::EditorError); - } - crate::git::git_commit_file(&description_filename)?; - self.read_description()?; - Ok(()) - } -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn read_comment_0() { - let comment_dir = - std::path::Path::new("test/0001/dd79c8cfb8beeacd0460429944b4ecbe95a31561/comments/9055dac36045fe36545bed7ae7b49347"); - 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"), - - dir: std::path::PathBuf::from(comment_dir), - }; - assert_eq!(comment, expected); - } -} diff --git a/src/issue.rs b/src/issue.rs index c762c82..f931be3 100644 --- a/src/issue.rs +++ b/src/issue.rs @@ -23,7 +23,6 @@ pub struct Issue { pub description: String, pub state: State, pub dependencies: Option>, - pub comments: std::collections::HashMap, /// This is the directory that the issue lives in. Only used /// internally by the entomologist library. @@ -34,8 +33,6 @@ pub struct Issue { pub enum IssueError { #[error(transparent)] StdIoError(#[from] std::io::Error), - #[error(transparent)] - CommentError(#[from] crate::comment::CommentError), #[error("Failed to parse issue")] IssueParseError, #[error("Failed to run git")] @@ -86,7 +83,6 @@ impl Issue { let mut description: Option = None; let mut state = State::New; // default state, if not specified in the issue let mut dependencies: Option> = None; - let mut comments = std::collections::HashMap::::new(); for direntry in dir.read_dir()? { if let Ok(direntry) = direntry { @@ -105,8 +101,6 @@ impl Issue { if deps.len() > 0 { dependencies = Some(deps); } - } else if file_name == "comments" && direntry.metadata()?.is_dir() { - Self::read_comments(&mut comments, &direntry.path())?; } else { #[cfg(feature = "log")] debug!("ignoring unknown file in issue directory: {:?}", file_name); @@ -122,43 +116,10 @@ impl Issue { description: description.unwrap(), state: state, dependencies, - comments, dir: std::path::PathBuf::from(dir), }) } - fn read_comments( - comments: &mut std::collections::HashMap, - 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); - } - } - Ok(()) - } - - pub fn new_comment(&mut self) -> Result { - let mut dir = std::path::PathBuf::from(&self.dir); - dir.push("comments"); - if !dir.exists() { - println!("creating {}", dir.to_string_lossy()); - std::fs::create_dir(&dir)?; - } - - let rnd: u128 = rand::random(); - dir.push(&format!("{:032x}", rnd)); - std::fs::create_dir(&dir)?; - - Ok(crate::comment::Comment { - description: String::from(""), // FIXME - dir, - }) - } - pub fn new(dir: &std::path::Path) -> Result { let mut issue_dir = std::path::PathBuf::from(dir); let rnd: u128 = rand::random(); @@ -168,7 +129,6 @@ 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::::new(), dir: issue_dir, }) } @@ -244,7 +204,6 @@ 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::::new(), dir: std::path::PathBuf::from(issue_dir), }; assert_eq!(issue, expected); @@ -258,7 +217,6 @@ mod tests { description: String::from("minimal"), state: State::InProgress, dependencies: None, - comments: std::collections::HashMap::::new(), dir: std::path::PathBuf::from(issue_dir), }; assert_eq!(issue, expected); diff --git a/src/issues.rs b/src/issues.rs index 28df2e9..2e40930 100644 --- a/src/issues.rs +++ b/src/issues.rs @@ -99,7 +99,6 @@ mod tests { description: String::from("minimal"), state: crate::issue::State::InProgress, dependencies: None, - comments: std::collections::HashMap::::new(), dir, }, ); @@ -113,7 +112,6 @@ 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: crate::issue::State::New, dependencies: None, - comments: std::collections::HashMap::::new(), dir, } ); @@ -136,7 +134,6 @@ mod tests { description: String::from("oh yeah we got titles"), state: crate::issue::State::Done, dependencies: None, - comments: std::collections::HashMap::::new(), dir, }, ); @@ -144,26 +141,12 @@ mod tests { let uuid = String::from("dd79c8cfb8beeacd0460429944b4ecbe95a31561"); let mut dir = std::path::PathBuf::from(issues_dir); dir.push(&uuid); - let mut comment_dir = dir.clone(); - let comment_uuid = String::from("9055dac36045fe36545bed7ae7b49347"); - comment_dir.push("comments"); - comment_dir.push(&comment_uuid); - let mut expected_comments = - std::collections::HashMap::::new(); - expected_comments.insert( - String::from(&comment_uuid), - crate::comment::Comment { - description: String::from("This is a comment on issue dd79c8cfb8beeacd0460429944b4ecbe95a31561\n\nIt has multiple lines\n"), - dir: std::path::PathBuf::from(comment_dir), - } - ); expected.add_issue( uuid, crate::issue::Issue { description: String::from("issues out the wazoo\n\nLots of words\nthat don't say much\nbecause this is just\na test\n"), state: crate::issue::State::WontDo, dependencies: None, - comments: expected_comments, dir, }, ); @@ -186,7 +169,6 @@ mod tests { description: String::from("oh yeah we got titles\n"), state: crate::issue::State::Done, dependencies: None, - comments: std::collections::HashMap::::new(), dir, }, ); @@ -200,7 +182,6 @@ mod tests { description: String::from("issues out the wazoo\n\nLots of words\nthat don't say much\nbecause this is just\na test\n"), state: crate::issue::State::WontDo, dependencies: None, - comments: std::collections::HashMap::::new(), dir, }, ); @@ -217,7 +198,6 @@ mod tests { crate::issue::IssueHandle::from("3fa5bfd93317ad25772680071d5ac3259cd2384f"), crate::issue::IssueHandle::from("dd79c8cfb8beeacd0460429944b4ecbe95a31561"), ]), - comments: std::collections::HashMap::::new(), dir, }, ); diff --git a/src/lib.rs b/src/lib.rs index e129eff..cca1c90 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,3 @@ -pub mod comment; pub mod git; pub mod issue; pub mod issues; diff --git a/test/0001/dd79c8cfb8beeacd0460429944b4ecbe95a31561/comments/9055dac36045fe36545bed7ae7b49347/description b/test/0001/dd79c8cfb8beeacd0460429944b4ecbe95a31561/comments/9055dac36045fe36545bed7ae7b49347/description deleted file mode 100644 index f9de678..0000000 --- a/test/0001/dd79c8cfb8beeacd0460429944b4ecbe95a31561/comments/9055dac36045fe36545bed7ae7b49347/description +++ /dev/null @@ -1,3 +0,0 @@ -This is a comment on issue dd79c8cfb8beeacd0460429944b4ecbe95a31561 - -It has multiple lines