"title" is just the first line of "description" now

This commit is contained in:
Sebastian Kuzminsky 2025-07-05 22:40:28 -06:00
parent 64022b16fa
commit 559e70077e
16 changed files with 40 additions and 44 deletions

View file

@ -34,7 +34,7 @@ fn handle_command(args: &Args, issues_dir: &std::path::Path) -> anyhow::Result<(
let issues = let issues =
entomologist::issues::Issues::new_from_dir(std::path::Path::new(issues_dir))?; entomologist::issues::Issues::new_from_dir(std::path::Path::new(issues_dir))?;
for (uuid, issue) in issues.issues.iter() { for (uuid, issue) in issues.issues.iter() {
println!("{} {} ({:?})", uuid, issue.title, issue.state); println!("{} {} ({:?})", uuid, issue.title(), issue.state);
} }
} }
Commands::New { title, description } => { Commands::New { title, description } => {

View file

@ -15,8 +15,7 @@ pub type IssueHandle = String;
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq)]
pub struct Issue { pub struct Issue {
pub title: String, pub description: String,
pub description: Option<String>,
pub state: State, pub state: State,
pub dependencies: Option<Vec<IssueHandle>>, pub dependencies: Option<Vec<IssueHandle>>,
} }
@ -53,7 +52,6 @@ impl FromStr for State {
impl Issue { impl Issue {
pub fn new_from_dir(dir: &std::path::Path) -> Result<Self, ReadIssueError> { 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 description: Option<String> = None;
let mut state = State::New; // default state, if not specified in the issue let mut state = State::New; // default state, if not specified in the issue
let mut dependencies: Option<Vec<String>> = None; let mut dependencies: Option<Vec<String>> = None;
@ -61,16 +59,17 @@ impl Issue {
for direntry in dir.read_dir()? { for direntry in dir.read_dir()? {
if let Ok(direntry) = direntry { if let Ok(direntry) = direntry {
let file_name = direntry.file_name(); let file_name = direntry.file_name();
if file_name == "title" { if file_name == "description" {
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())?); description = Some(std::fs::read_to_string(direntry.path())?);
} else if file_name == "state" { } else if file_name == "state" {
let state_string = std::fs::read_to_string(direntry.path())?; 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" { } else if file_name == "dependencies" {
let dep_strings = std::fs::read_to_string(direntry.path())?; 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 { if deps.len() > 0 {
dependencies = Some(deps); dependencies = Some(deps);
} }
@ -80,17 +79,23 @@ impl Issue {
} }
} }
if title == None { if description == None {
return Err(ReadIssueError::IssueParseError); return Err(ReadIssueError::IssueParseError);
} }
Ok(Self { Ok(Self {
title: title.unwrap(), description: description.unwrap(),
description: description,
state: state, state: state,
dependencies, 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)] #[cfg(test)]
@ -102,8 +107,7 @@ mod tests {
let issue_dir = std::path::Path::new("test/0000/3943fc5c173fdf41c0a22251593cd476d96e6c9f/"); let issue_dir = std::path::Path::new("test/0000/3943fc5c173fdf41c0a22251593cd476d96e6c9f/");
let issue = Issue::new_from_dir(issue_dir).unwrap(); let issue = Issue::new_from_dir(issue_dir).unwrap();
let expected = Issue { let expected = Issue {
title: String::from("this is the title of my 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"),
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, state: State::New,
dependencies: None, dependencies: None,
}; };
@ -115,8 +119,7 @@ mod tests {
let issue_dir = std::path::Path::new("test/0000/7792b063eef6d33e7da5dc1856750c149ba678c6/"); let issue_dir = std::path::Path::new("test/0000/7792b063eef6d33e7da5dc1856750c149ba678c6/");
let issue = Issue::new_from_dir(issue_dir).unwrap(); let issue = Issue::new_from_dir(issue_dir).unwrap();
let expected = Issue { let expected = Issue {
title: String::from("minimal"), description: String::from("minimal"),
description: None,
state: State::InProgress, state: State::InProgress,
dependencies: None, dependencies: None,
}; };

View file

@ -80,8 +80,7 @@ mod tests {
expected.add_issue( expected.add_issue(
String::from("7792b063eef6d33e7da5dc1856750c149ba678c6"), String::from("7792b063eef6d33e7da5dc1856750c149ba678c6"),
crate::issue::Issue { crate::issue::Issue {
title: String::from("minimal"), description: String::from("minimal"),
description: None,
state: crate::issue::State::InProgress, state: crate::issue::State::InProgress,
dependencies: None, dependencies: None,
}, },
@ -89,8 +88,7 @@ mod tests {
expected.add_issue( expected.add_issue(
String::from("3943fc5c173fdf41c0a22251593cd476d96e6c9f"), String::from("3943fc5c173fdf41c0a22251593cd476d96e6c9f"),
crate::issue::Issue { crate::issue::Issue {
title: String::from("this is the title of my 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"),
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, state: crate::issue::State::New,
dependencies: None, dependencies: None,
} }
@ -107,8 +105,7 @@ mod tests {
expected.add_issue( expected.add_issue(
String::from("3fa5bfd93317ad25772680071d5ac3259cd2384f"), String::from("3fa5bfd93317ad25772680071d5ac3259cd2384f"),
crate::issue::Issue { crate::issue::Issue {
title: String::from("oh yeah we got titles"), description: String::from("oh yeah we got titles"),
description: None,
state: crate::issue::State::Done, state: crate::issue::State::Done,
dependencies: None, dependencies: None,
}, },
@ -116,10 +113,7 @@ mod tests {
expected.add_issue( expected.add_issue(
String::from("dd79c8cfb8beeacd0460429944b4ecbe95a31561"), String::from("dd79c8cfb8beeacd0460429944b4ecbe95a31561"),
crate::issue::Issue { crate::issue::Issue {
title: String::from("issues out the wazoo"), description: String::from("issues out the wazoo\n\nLots of words\nthat don't say much\nbecause this is just\na test\n"),
description: Some(String::from(
"Lots of words\nthat don't say much\nbecause this is just\na test\n",
)),
state: crate::issue::State::WontDo, state: crate::issue::State::WontDo,
dependencies: None, dependencies: None,
}, },
@ -136,8 +130,7 @@ mod tests {
expected.add_issue( expected.add_issue(
String::from("3fa5bfd93317ad25772680071d5ac3259cd2384f"), String::from("3fa5bfd93317ad25772680071d5ac3259cd2384f"),
crate::issue::Issue { crate::issue::Issue {
title: String::from("oh yeah we got titles"), description: String::from("oh yeah we got titles\n"),
description: None,
state: crate::issue::State::Done, state: crate::issue::State::Done,
dependencies: None, dependencies: None,
}, },
@ -145,10 +138,7 @@ mod tests {
expected.add_issue( expected.add_issue(
String::from("dd79c8cfb8beeacd0460429944b4ecbe95a31561"), String::from("dd79c8cfb8beeacd0460429944b4ecbe95a31561"),
crate::issue::Issue { crate::issue::Issue {
title: String::from("issues out the wazoo"), description: String::from("issues out the wazoo\n\nLots of words\nthat don't say much\nbecause this is just\na test\n"),
description: Some(String::from(
"Lots of words\nthat don't say much\nbecause this is just\na test\n",
)),
state: crate::issue::State::WontDo, state: crate::issue::State::WontDo,
dependencies: None, dependencies: None,
}, },
@ -156,15 +146,14 @@ mod tests {
expected.add_issue( expected.add_issue(
String::from("a85f81fc5f14cb5d4851dd445dc9744c7f16ccc7"), String::from("a85f81fc5f14cb5d4851dd445dc9744c7f16ccc7"),
crate::issue::Issue { crate::issue::Issue {
title: String::from("issue with dependencies"), description: String::from("issue with dependencies\n\na test has begun\nfor dependencies we seek\nintertwining life"),
description: Some(String::from(
"a test has begun\nfor dependencies we seek\nintertwining life",
)),
state: crate::issue::State::WontDo, 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); assert_eq!(issues, expected);
} }
} }

View file

@ -1,3 +1,5 @@
this is the title of my issue
This is the description of my issue. This is the description of my issue.
It is multiple lines. It is multiple lines.
* Arbitrary contents * Arbitrary contents

View file

@ -1 +0,0 @@
this is the title of my issue

View file

@ -0,0 +1 @@
minimal

View file

@ -0,0 +1 @@
oh yeah we got titles

View file

@ -1,3 +1,5 @@
issues out the wazoo
Lots of words Lots of words
that don't say much that don't say much
because this is just because this is just

View file

@ -1 +0,0 @@
issues out the wazoo

View file

@ -1 +0,0 @@
oh yeah we got titles

View file

@ -1,3 +1,5 @@
issue with dependencies
a test has begun a test has begun
for dependencies we seek for dependencies we seek
intertwining life intertwining life

View file

@ -1 +0,0 @@
issue with dependencies

View file

@ -1,3 +1,5 @@
issues out the wazoo
Lots of words Lots of words
that don't say much that don't say much
because this is just because this is just

View file

@ -1 +0,0 @@
issues out the wazoo