"title" is just the first line of "description" now
This commit is contained in:
parent
64022b16fa
commit
559e70077e
16 changed files with 40 additions and 44 deletions
|
|
@ -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 } => {
|
||||
|
|
|
|||
31
src/issue.rs
31
src/issue.rs
|
|
@ -15,8 +15,7 @@ pub type IssueHandle = String;
|
|||
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub struct Issue {
|
||||
pub title: String,
|
||||
pub description: Option<String>,
|
||||
pub description: String,
|
||||
pub state: State,
|
||||
pub dependencies: Option<Vec<IssueHandle>>,
|
||||
}
|
||||
|
|
@ -53,7 +52,6 @@ impl FromStr for State {
|
|||
|
||||
impl Issue {
|
||||
pub fn new_from_dir(dir: &std::path::Path) -> Result<Self, ReadIssueError> {
|
||||
let mut title: Option<String> = None;
|
||||
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;
|
||||
|
|
@ -61,16 +59,17 @@ impl Issue {
|
|||
for direntry in dir.read_dir()? {
|
||||
if let Ok(direntry) = direntry {
|
||||
let file_name = direntry.file_name();
|
||||
if file_name == "title" {
|
||||
title = Some(std::fs::read_to_string(direntry.path())?.trim().into());
|
||||
} else if file_name == "description" {
|
||||
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())?;
|
||||
} else if file_name == "dependencies" {
|
||||
let dep_strings = std::fs::read_to_string(direntry.path())?;
|
||||
let deps: Vec<IssueHandle> = dep_strings.lines().map(|dep|{IssueHandle::from(dep)}).collect();
|
||||
let deps: Vec<IssueHandle> = dep_strings
|
||||
.lines()
|
||||
.map(|dep| IssueHandle::from(dep))
|
||||
.collect();
|
||||
if deps.len() > 0 {
|
||||
dependencies = Some(deps);
|
||||
}
|
||||
|
|
@ -80,17 +79,23 @@ impl Issue {
|
|||
}
|
||||
}
|
||||
|
||||
if title == None {
|
||||
if description == None {
|
||||
return Err(ReadIssueError::IssueParseError);
|
||||
}
|
||||
|
||||
Ok(Self {
|
||||
title: title.unwrap(),
|
||||
description: description,
|
||||
description: description.unwrap(),
|
||||
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)]
|
||||
|
|
@ -102,8 +107,7 @@ mod tests {
|
|||
let issue_dir = std::path::Path::new("test/0000/3943fc5c173fdf41c0a22251593cd476d96e6c9f/");
|
||||
let issue = Issue::new_from_dir(issue_dir).unwrap();
|
||||
let expected = Issue {
|
||||
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")),
|
||||
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,
|
||||
};
|
||||
|
|
@ -115,8 +119,7 @@ mod tests {
|
|||
let issue_dir = std::path::Path::new("test/0000/7792b063eef6d33e7da5dc1856750c149ba678c6/");
|
||||
let issue = Issue::new_from_dir(issue_dir).unwrap();
|
||||
let expected = Issue {
|
||||
title: String::from("minimal"),
|
||||
description: None,
|
||||
description: String::from("minimal"),
|
||||
state: State::InProgress,
|
||||
dependencies: None,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -80,8 +80,7 @@ mod tests {
|
|||
expected.add_issue(
|
||||
String::from("7792b063eef6d33e7da5dc1856750c149ba678c6"),
|
||||
crate::issue::Issue {
|
||||
title: String::from("minimal"),
|
||||
description: None,
|
||||
description: String::from("minimal"),
|
||||
state: crate::issue::State::InProgress,
|
||||
dependencies: None,
|
||||
},
|
||||
|
|
@ -89,8 +88,7 @@ mod tests {
|
|||
expected.add_issue(
|
||||
String::from("3943fc5c173fdf41c0a22251593cd476d96e6c9f"),
|
||||
crate::issue::Issue {
|
||||
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")),
|
||||
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,
|
||||
}
|
||||
|
|
@ -107,8 +105,7 @@ mod tests {
|
|||
expected.add_issue(
|
||||
String::from("3fa5bfd93317ad25772680071d5ac3259cd2384f"),
|
||||
crate::issue::Issue {
|
||||
title: String::from("oh yeah we got titles"),
|
||||
description: None,
|
||||
description: String::from("oh yeah we got titles"),
|
||||
state: crate::issue::State::Done,
|
||||
dependencies: None,
|
||||
},
|
||||
|
|
@ -116,10 +113,7 @@ mod tests {
|
|||
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",
|
||||
)),
|
||||
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,
|
||||
},
|
||||
|
|
@ -136,8 +130,7 @@ mod tests {
|
|||
expected.add_issue(
|
||||
String::from("3fa5bfd93317ad25772680071d5ac3259cd2384f"),
|
||||
crate::issue::Issue {
|
||||
title: String::from("oh yeah we got titles"),
|
||||
description: None,
|
||||
description: String::from("oh yeah we got titles\n"),
|
||||
state: crate::issue::State::Done,
|
||||
dependencies: None,
|
||||
},
|
||||
|
|
@ -145,10 +138,7 @@ mod tests {
|
|||
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",
|
||||
)),
|
||||
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,
|
||||
},
|
||||
|
|
@ -156,15 +146,14 @@ mod tests {
|
|||
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",
|
||||
)),
|
||||
description: String::from("issue with dependencies\n\na 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
this is the title of my issue
|
||||
|
||||
This is the description of my issue.
|
||||
It is multiple lines.
|
||||
* Arbitrary contents
|
||||
|
|
|
|||
|
|
@ -1 +0,0 @@
|
|||
this is the title of my issue
|
||||
|
|
@ -0,0 +1 @@
|
|||
minimal
|
||||
|
|
@ -1 +0,0 @@
|
|||
minimal
|
||||
|
|
@ -0,0 +1 @@
|
|||
oh yeah we got titles
|
||||
|
|
@ -1,3 +1,5 @@
|
|||
issues out the wazoo
|
||||
|
||||
Lots of words
|
||||
that don't say much
|
||||
because this is just
|
||||
|
|
|
|||
|
|
@ -1 +0,0 @@
|
|||
issues out the wazoo
|
||||
|
|
@ -1 +0,0 @@
|
|||
oh yeah we got titles
|
||||
|
|
@ -1,3 +1,5 @@
|
|||
issue with dependencies
|
||||
|
||||
a test has begun
|
||||
for dependencies we seek
|
||||
intertwining life
|
||||
|
|
@ -1 +0,0 @@
|
|||
issue with dependencies
|
||||
|
|
@ -1,3 +1,5 @@
|
|||
issues out the wazoo
|
||||
|
||||
Lots of words
|
||||
that don't say much
|
||||
because this is just
|
||||
|
|
|
|||
|
|
@ -1 +0,0 @@
|
|||
issues out the wazoo
|
||||
Loading…
Add table
Add a link
Reference in a new issue