diff --git a/src/bin/ent/main.rs b/src/bin/ent/main.rs index 65e36dc..86dfa95 100644 --- a/src/bin/ent/main.rs +++ b/src/bin/ent/main.rs @@ -34,7 +34,7 @@ fn handle_command(args: &Args, issues_dir: &std::path::Path) -> anyhow::Result<( let issues = entomologist::issues::Issues::new_from_dir(std::path::Path::new(issues_dir))?; for (uuid, issue) in issues.issues.iter() { - println!("{} {} ({:?})", uuid, issue.title(), issue.state); + println!("{} {} ({:?})", uuid, issue.title, issue.state); } } Commands::New { title, description } => { diff --git a/src/issue.rs b/src/issue.rs index 939af47..7171380 100644 --- a/src/issue.rs +++ b/src/issue.rs @@ -15,7 +15,8 @@ pub type IssueHandle = String; #[derive(Debug, PartialEq)] pub struct Issue { - pub description: String, + pub title: String, + pub description: Option, pub state: State, pub dependencies: Option>, } @@ -52,6 +53,7 @@ impl FromStr for State { impl Issue { pub fn new_from_dir(dir: &std::path::Path) -> Result { + let mut title: Option = None; let mut description: Option = None; let mut state = State::New; // default state, if not specified in the issue let mut dependencies: Option> = None; @@ -59,17 +61,16 @@ impl Issue { for direntry in dir.read_dir()? { if let Ok(direntry) = direntry { let file_name = direntry.file_name(); - if file_name == "description" { + if file_name == "title" { + title = Some(std::fs::read_to_string(direntry.path())?.trim().into()); + } else if file_name == "description" { description = Some(std::fs::read_to_string(direntry.path())?); } else if file_name == "state" { let state_string = std::fs::read_to_string(direntry.path())?; - state = State::from_str(state_string.trim())?; + state = State::from_str(state_string.trim())?; } else if file_name == "dependencies" { let dep_strings = std::fs::read_to_string(direntry.path())?; - let deps: Vec = dep_strings - .lines() - .map(|dep| IssueHandle::from(dep)) - .collect(); + let deps: Vec = dep_strings.lines().map(|dep|{IssueHandle::from(dep)}).collect(); if deps.len() > 0 { dependencies = Some(deps); } @@ -79,23 +80,17 @@ impl Issue { } } - if description == None { + if title == None { return Err(ReadIssueError::IssueParseError); } Ok(Self { - description: description.unwrap(), + title: title.unwrap(), + description: description, state: state, dependencies, }) } - - pub fn title<'a>(&'a self) -> &'a str { - match self.description.find("\n") { - Some(index) => &self.description.as_str()[..index], - None => self.description.as_str(), - } - } } #[cfg(test)] @@ -107,7 +102,8 @@ mod tests { let issue_dir = std::path::Path::new("test/0000/3943fc5c173fdf41c0a22251593cd476d96e6c9f/"); let issue = Issue::new_from_dir(issue_dir).unwrap(); let expected = Issue { - 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"), + title: String::from("this is the title of my issue"), + description: Some(String::from("This 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, }; @@ -119,7 +115,8 @@ mod tests { let issue_dir = std::path::Path::new("test/0000/7792b063eef6d33e7da5dc1856750c149ba678c6/"); let issue = Issue::new_from_dir(issue_dir).unwrap(); let expected = Issue { - description: String::from("minimal"), + title: String::from("minimal"), + description: None, state: State::InProgress, dependencies: None, }; diff --git a/src/issues.rs b/src/issues.rs index 9422ded..35116e7 100644 --- a/src/issues.rs +++ b/src/issues.rs @@ -80,7 +80,8 @@ mod tests { expected.add_issue( String::from("7792b063eef6d33e7da5dc1856750c149ba678c6"), crate::issue::Issue { - description: String::from("minimal"), + title: String::from("minimal"), + description: None, state: crate::issue::State::InProgress, dependencies: None, }, @@ -88,7 +89,8 @@ mod tests { expected.add_issue( String::from("3943fc5c173fdf41c0a22251593cd476d96e6c9f"), crate::issue::Issue { - 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"), + title: String::from("this is the title of my issue"), + description: Some(String::from("This 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, } @@ -105,7 +107,8 @@ mod tests { expected.add_issue( String::from("3fa5bfd93317ad25772680071d5ac3259cd2384f"), crate::issue::Issue { - description: String::from("oh yeah we got titles"), + title: String::from("oh yeah we got titles"), + description: None, state: crate::issue::State::Done, dependencies: None, }, @@ -113,7 +116,10 @@ mod tests { expected.add_issue( String::from("dd79c8cfb8beeacd0460429944b4ecbe95a31561"), 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"), + title: String::from("issues out the wazoo"), + description: Some(String::from( + "Lots of words\nthat don't say much\nbecause this is just\na test\n", + )), state: crate::issue::State::WontDo, dependencies: None, }, @@ -130,7 +136,8 @@ mod tests { expected.add_issue( String::from("3fa5bfd93317ad25772680071d5ac3259cd2384f"), crate::issue::Issue { - description: String::from("oh yeah we got titles\n"), + title: String::from("oh yeah we got titles"), + description: None, state: crate::issue::State::Done, dependencies: None, }, @@ -138,7 +145,10 @@ mod tests { expected.add_issue( String::from("dd79c8cfb8beeacd0460429944b4ecbe95a31561"), 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"), + title: String::from("issues out the wazoo"), + description: Some(String::from( + "Lots of words\nthat don't say much\nbecause this is just\na test\n", + )), state: crate::issue::State::WontDo, dependencies: None, }, @@ -146,14 +156,15 @@ mod tests { expected.add_issue( String::from("a85f81fc5f14cb5d4851dd445dc9744c7f16ccc7"), crate::issue::Issue { - description: String::from("issue with dependencies\n\na test has begun\nfor dependencies we seek\nintertwining life"), + title: String::from("issue with dependencies"), + description: Some(String::from( + "a test has begun\nfor dependencies we seek\nintertwining life", + )), state: crate::issue::State::WontDo, - dependencies: Some(vec![ - crate::issue::IssueHandle::from("3fa5bfd93317ad25772680071d5ac3259cd2384f"), - crate::issue::IssueHandle::from("dd79c8cfb8beeacd0460429944b4ecbe95a31561"), - ]), + dependencies: Some(vec![crate::issue::IssueHandle::from("3fa5bfd93317ad25772680071d5ac3259cd2384f"), crate::issue::IssueHandle::from("dd79c8cfb8beeacd0460429944b4ecbe95a31561")]), }, ); assert_eq!(issues, expected); } } + diff --git a/test/0000/3943fc5c173fdf41c0a22251593cd476d96e6c9f/description b/test/0000/3943fc5c173fdf41c0a22251593cd476d96e6c9f/description index e380829..3db0fcf 100644 --- a/test/0000/3943fc5c173fdf41c0a22251593cd476d96e6c9f/description +++ b/test/0000/3943fc5c173fdf41c0a22251593cd476d96e6c9f/description @@ -1,5 +1,3 @@ -this is the title of my issue - This is the description of my issue. It is multiple lines. * Arbitrary contents diff --git a/test/0000/3943fc5c173fdf41c0a22251593cd476d96e6c9f/title b/test/0000/3943fc5c173fdf41c0a22251593cd476d96e6c9f/title new file mode 100644 index 0000000..c9c2379 --- /dev/null +++ b/test/0000/3943fc5c173fdf41c0a22251593cd476d96e6c9f/title @@ -0,0 +1 @@ +this is the title of my issue diff --git a/test/0000/7792b063eef6d33e7da5dc1856750c149ba678c6/description b/test/0000/7792b063eef6d33e7da5dc1856750c149ba678c6/description deleted file mode 100644 index 982085a..0000000 --- a/test/0000/7792b063eef6d33e7da5dc1856750c149ba678c6/description +++ /dev/null @@ -1 +0,0 @@ -minimal \ No newline at end of file diff --git a/test/0000/7792b063eef6d33e7da5dc1856750c149ba678c6/title b/test/0000/7792b063eef6d33e7da5dc1856750c149ba678c6/title new file mode 100644 index 0000000..dd1a932 --- /dev/null +++ b/test/0000/7792b063eef6d33e7da5dc1856750c149ba678c6/title @@ -0,0 +1 @@ +minimal diff --git a/test/0001/3fa5bfd93317ad25772680071d5ac3259cd2384f/description b/test/0001/3fa5bfd93317ad25772680071d5ac3259cd2384f/description deleted file mode 100644 index c73d593..0000000 --- a/test/0001/3fa5bfd93317ad25772680071d5ac3259cd2384f/description +++ /dev/null @@ -1 +0,0 @@ -oh yeah we got titles \ No newline at end of file diff --git a/test/0002/3fa5bfd93317ad25772680071d5ac3259cd2384f/description b/test/0001/3fa5bfd93317ad25772680071d5ac3259cd2384f/title similarity index 100% rename from test/0002/3fa5bfd93317ad25772680071d5ac3259cd2384f/description rename to test/0001/3fa5bfd93317ad25772680071d5ac3259cd2384f/title diff --git a/test/0001/dd79c8cfb8beeacd0460429944b4ecbe95a31561/description b/test/0001/dd79c8cfb8beeacd0460429944b4ecbe95a31561/description index a65ceb6..010156b 100644 --- a/test/0001/dd79c8cfb8beeacd0460429944b4ecbe95a31561/description +++ b/test/0001/dd79c8cfb8beeacd0460429944b4ecbe95a31561/description @@ -1,5 +1,3 @@ -issues out the wazoo - Lots of words that don't say much because this is just diff --git a/test/0001/dd79c8cfb8beeacd0460429944b4ecbe95a31561/title b/test/0001/dd79c8cfb8beeacd0460429944b4ecbe95a31561/title new file mode 100644 index 0000000..ab5b4a9 --- /dev/null +++ b/test/0001/dd79c8cfb8beeacd0460429944b4ecbe95a31561/title @@ -0,0 +1 @@ +issues out the wazoo diff --git a/test/0002/3fa5bfd93317ad25772680071d5ac3259cd2384f/title b/test/0002/3fa5bfd93317ad25772680071d5ac3259cd2384f/title new file mode 100644 index 0000000..18a1926 --- /dev/null +++ b/test/0002/3fa5bfd93317ad25772680071d5ac3259cd2384f/title @@ -0,0 +1 @@ +oh yeah we got titles diff --git a/test/0002/a85f81fc5f14cb5d4851dd445dc9744c7f16ccc7/description b/test/0002/a85f81fc5f14cb5d4851dd445dc9744c7f16ccc7/description index 42e2ce3..049c15f 100644 --- a/test/0002/a85f81fc5f14cb5d4851dd445dc9744c7f16ccc7/description +++ b/test/0002/a85f81fc5f14cb5d4851dd445dc9744c7f16ccc7/description @@ -1,5 +1,3 @@ -issue with dependencies - a test has begun for dependencies we seek intertwining life \ No newline at end of file diff --git a/test/0002/a85f81fc5f14cb5d4851dd445dc9744c7f16ccc7/title b/test/0002/a85f81fc5f14cb5d4851dd445dc9744c7f16ccc7/title new file mode 100644 index 0000000..7c150e7 --- /dev/null +++ b/test/0002/a85f81fc5f14cb5d4851dd445dc9744c7f16ccc7/title @@ -0,0 +1 @@ +issue with dependencies diff --git a/test/0002/dd79c8cfb8beeacd0460429944b4ecbe95a31561/description b/test/0002/dd79c8cfb8beeacd0460429944b4ecbe95a31561/description index a65ceb6..010156b 100644 --- a/test/0002/dd79c8cfb8beeacd0460429944b4ecbe95a31561/description +++ b/test/0002/dd79c8cfb8beeacd0460429944b4ecbe95a31561/description @@ -1,5 +1,3 @@ -issues out the wazoo - Lots of words that don't say much because this is just diff --git a/test/0002/dd79c8cfb8beeacd0460429944b4ecbe95a31561/title b/test/0002/dd79c8cfb8beeacd0460429944b4ecbe95a31561/title new file mode 100644 index 0000000..ab5b4a9 --- /dev/null +++ b/test/0002/dd79c8cfb8beeacd0460429944b4ecbe95a31561/title @@ -0,0 +1 @@ +issues out the wazoo