diff --git a/src/issue.rs b/src/issue.rs index 6dde005..7171380 100644 --- a/src/issue.rs +++ b/src/issue.rs @@ -5,16 +5,20 @@ use std::str::FromStr; pub enum State { New, Backlog, + Blocked, InProgress, Done, WontDo, } +pub type IssueHandle = String; + #[derive(Debug, PartialEq)] pub struct Issue { pub title: String, pub description: Option, pub state: State, + pub dependencies: Option>, } #[derive(Debug, thiserror::Error)] @@ -33,6 +37,8 @@ impl FromStr for State { Ok(State::New) } else if s == "backlog" { Ok(State::Backlog) + } else if s == "blocked" { + Ok(State::Blocked) } else if s == "inprogress" { Ok(State::InProgress) } else if s == "done" { @@ -50,6 +56,7 @@ impl Issue { 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; for direntry in dir.read_dir()? { if let Ok(direntry) = direntry { @@ -60,7 +67,13 @@ impl Issue { 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(); + if deps.len() > 0 { + dependencies = Some(deps); + } } else { println!("ignoring unknown file in issue directory: {:?}", file_name); } @@ -75,6 +88,7 @@ impl Issue { title: title.unwrap(), description: description, state: state, + dependencies, }) } } @@ -91,6 +105,7 @@ mod tests { 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, }; assert_eq!(issue, expected); } @@ -103,6 +118,7 @@ mod tests { title: String::from("minimal"), description: None, state: State::InProgress, + dependencies: None, }; assert_eq!(issue, expected); } diff --git a/src/issues.rs b/src/issues.rs index b5c1c87..35116e7 100644 --- a/src/issues.rs +++ b/src/issues.rs @@ -83,6 +83,7 @@ mod tests { title: String::from("minimal"), description: None, state: crate::issue::State::InProgress, + dependencies: None, }, ); expected.add_issue( @@ -91,6 +92,7 @@ mod tests { 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, } ); assert_eq!(issues, expected); @@ -108,6 +110,7 @@ mod tests { title: String::from("oh yeah we got titles"), description: None, state: crate::issue::State::Done, + dependencies: None, }, ); expected.add_issue( @@ -118,8 +121,50 @@ mod tests { "Lots of words\nthat don't say much\nbecause this is just\na test\n", )), state: crate::issue::State::WontDo, + dependencies: None, + }, + ); + assert_eq!(issues, expected); + } + + #[test] + fn read_issues_0002() { + let issues_dir = std::path::Path::new("test/0002/"); + let issues = Issues::new_from_dir(issues_dir).unwrap(); + + let mut expected = Issues::new(); + expected.add_issue( + String::from("3fa5bfd93317ad25772680071d5ac3259cd2384f"), + crate::issue::Issue { + title: String::from("oh yeah we got titles"), + description: None, + state: crate::issue::State::Done, + dependencies: None, + }, + ); + expected.add_issue( + String::from("dd79c8cfb8beeacd0460429944b4ecbe95a31561"), + crate::issue::Issue { + 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, + }, + ); + expected.add_issue( + String::from("a85f81fc5f14cb5d4851dd445dc9744c7f16ccc7"), + crate::issue::Issue { + 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")]), }, ); assert_eq!(issues, expected); } } + diff --git a/test/0002/3fa5bfd93317ad25772680071d5ac3259cd2384f/state b/test/0002/3fa5bfd93317ad25772680071d5ac3259cd2384f/state new file mode 100644 index 0000000..19f86f4 --- /dev/null +++ b/test/0002/3fa5bfd93317ad25772680071d5ac3259cd2384f/state @@ -0,0 +1 @@ +done 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/dependencies b/test/0002/a85f81fc5f14cb5d4851dd445dc9744c7f16ccc7/dependencies new file mode 100644 index 0000000..71e4ee3 --- /dev/null +++ b/test/0002/a85f81fc5f14cb5d4851dd445dc9744c7f16ccc7/dependencies @@ -0,0 +1,2 @@ +3fa5bfd93317ad25772680071d5ac3259cd2384f +dd79c8cfb8beeacd0460429944b4ecbe95a31561 \ No newline at end of file diff --git a/test/0002/a85f81fc5f14cb5d4851dd445dc9744c7f16ccc7/description b/test/0002/a85f81fc5f14cb5d4851dd445dc9744c7f16ccc7/description new file mode 100644 index 0000000..049c15f --- /dev/null +++ b/test/0002/a85f81fc5f14cb5d4851dd445dc9744c7f16ccc7/description @@ -0,0 +1,3 @@ +a test has begun +for dependencies we seek +intertwining life \ No newline at end of file diff --git a/test/0002/a85f81fc5f14cb5d4851dd445dc9744c7f16ccc7/state b/test/0002/a85f81fc5f14cb5d4851dd445dc9744c7f16ccc7/state new file mode 100644 index 0000000..7f19192 --- /dev/null +++ b/test/0002/a85f81fc5f14cb5d4851dd445dc9744c7f16ccc7/state @@ -0,0 +1 @@ +wontdo 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/config.toml b/test/0002/config.toml new file mode 100644 index 0000000..dfc15f2 --- /dev/null +++ b/test/0002/config.toml @@ -0,0 +1 @@ +states = [ "open", "closed" ] diff --git a/test/0002/dd79c8cfb8beeacd0460429944b4ecbe95a31561/description b/test/0002/dd79c8cfb8beeacd0460429944b4ecbe95a31561/description new file mode 100644 index 0000000..010156b --- /dev/null +++ b/test/0002/dd79c8cfb8beeacd0460429944b4ecbe95a31561/description @@ -0,0 +1,4 @@ +Lots of words +that don't say much +because this is just +a test diff --git a/test/0002/dd79c8cfb8beeacd0460429944b4ecbe95a31561/state b/test/0002/dd79c8cfb8beeacd0460429944b4ecbe95a31561/state new file mode 100644 index 0000000..7f19192 --- /dev/null +++ b/test/0002/dd79c8cfb8beeacd0460429944b4ecbe95a31561/state @@ -0,0 +1 @@ +wontdo 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