Add ID field to Issue Struct #22
2 changed files with 70 additions and 63 deletions
23
src/issue.rs
23
src/issue.rs
|
|
@ -20,6 +20,7 @@ pub type IssueHandle = String;
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq)]
|
||||||
pub struct Issue {
|
pub struct Issue {
|
||||||
|
pub id: String,
|
||||||
pub author: String,
|
pub author: String,
|
||||||
pub timestamp: chrono::DateTime<chrono::Local>,
|
pub timestamp: chrono::DateTime<chrono::Local>,
|
||||||
pub tags: Vec<String>,
|
pub tags: Vec<String>,
|
||||||
|
|
@ -56,6 +57,8 @@ pub enum IssueError {
|
||||||
TagNotFound(String),
|
TagNotFound(String),
|
||||||
#[error("stdin/stdout is not a terminal")]
|
#[error("stdin/stdout is not a terminal")]
|
||||||
StdioIsNotTerminal,
|
StdioIsNotTerminal,
|
||||||
|
#[error("Failed to parse issue ID")]
|
||||||
|
IdError,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FromStr for State {
|
impl FromStr for State {
|
||||||
|
|
@ -145,10 +148,21 @@ impl Issue {
|
||||||
return Err(IssueError::IssueParseError);
|
return Err(IssueError::IssueParseError);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// parse the issue ID from the directory name
|
||||||
|
let id = if let Some(parsed_id) = match dir.file_name() {
|
||||||
|
Some(name) => name.to_str(),
|
||||||
|
None => Err(IssueError::IdError)?,
|
||||||
|
} {
|
||||||
|
String::from(parsed_id)
|
||||||
|
} else {
|
||||||
|
Err(IssueError::IdError)?
|
||||||
|
};
|
||||||
|
|
||||||
let author = crate::git::git_log_oldest_author(dir)?;
|
let author = crate::git::git_log_oldest_author(dir)?;
|
||||||
let timestamp = crate::git::git_log_oldest_timestamp(dir)?;
|
let timestamp = crate::git::git_log_oldest_timestamp(dir)?;
|
||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
|
id,
|
||||||
author,
|
author,
|
||||||
timestamp,
|
timestamp,
|
||||||
tags,
|
tags,
|
||||||
|
|
@ -204,6 +218,7 @@ impl Issue {
|
||||||
std::fs::create_dir(&issue_dir)?;
|
std::fs::create_dir(&issue_dir)?;
|
||||||
|
|
||||||
let mut issue = Self {
|
let mut issue = Self {
|
||||||
|
id: String::from(&issue_id),
|
||||||
author: String::from(""),
|
author: String::from(""),
|
||||||
timestamp: chrono::Local::now(),
|
timestamp: chrono::Local::now(),
|
||||||
tags: Vec::<String>::new(),
|
tags: Vec::<String>::new(),
|
||||||
|
|
@ -444,6 +459,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 {
|
||||||
|
id: String::from("3943fc5c173fdf41c0a22251593cd476d96e6c9f"),
|
||||||
author: String::from("Sebastian Kuzminsky <seb@highlab.com>"),
|
author: String::from("Sebastian Kuzminsky <seb@highlab.com>"),
|
||||||
timestamp: chrono::DateTime::parse_from_rfc3339("2025-07-03T12:14:26-06:00")
|
timestamp: chrono::DateTime::parse_from_rfc3339("2025-07-03T12:14:26-06:00")
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
|
@ -451,12 +467,14 @@ mod tests {
|
||||||
tags: Vec::<String>::from([
|
tags: Vec::<String>::from([
|
||||||
String::from("tag1"),
|
String::from("tag1"),
|
||||||
String::from("TAG2"),
|
String::from("TAG2"),
|
||||||
String::from("i-am-also-a-tag")
|
String::from("i-am-also-a-tag"),
|
||||||
]),
|
]),
|
||||||
state: State::New,
|
state: State::New,
|
||||||
dependencies: None,
|
dependencies: None,
|
||||||
assignee: None,
|
assignee: None,
|
||||||
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: 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",
|
||||||
|
),
|
||||||
comments: Vec::<crate::comment::Comment>::new(),
|
comments: Vec::<crate::comment::Comment>::new(),
|
||||||
dir: std::path::PathBuf::from(issue_dir),
|
dir: std::path::PathBuf::from(issue_dir),
|
||||||
};
|
};
|
||||||
|
|
@ -468,6 +486,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 {
|
||||||
|
id: String::from("7792b063eef6d33e7da5dc1856750c149ba678c6"),
|
||||||
author: String::from("Sebastian Kuzminsky <seb@highlab.com>"),
|
author: String::from("Sebastian Kuzminsky <seb@highlab.com>"),
|
||||||
timestamp: chrono::DateTime::parse_from_rfc3339("2025-07-03T12:14:26-06:00")
|
timestamp: chrono::DateTime::parse_from_rfc3339("2025-07-03T12:14:26-06:00")
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
|
|
||||||
110
src/issues.rs
110
src/issues.rs
|
|
@ -31,8 +31,8 @@ impl Issues {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_issue(&mut self, uuid: String, issue: crate::issue::Issue) {
|
pub fn add_issue(&mut self, issue: crate::issue::Issue) {
|
||||||
self.issues.insert(uuid, issue);
|
self.issues.insert(issue.id.clone(), issue);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_issue(&self, issue_id: &str) -> Option<&crate::issue::Issue> {
|
pub fn get_issue(&self, issue_id: &str) -> Option<&crate::issue::Issue> {
|
||||||
|
|
@ -56,14 +56,8 @@ impl Issues {
|
||||||
for direntry in dir.read_dir()? {
|
for direntry in dir.read_dir()? {
|
||||||
if let Ok(direntry) = direntry {
|
if let Ok(direntry) = direntry {
|
||||||
if direntry.metadata()?.is_dir() {
|
if direntry.metadata()?.is_dir() {
|
||||||
let uuid = match direntry.file_name().into_string() {
|
|
||||||
Ok(uuid) => uuid,
|
|
||||||
Err(orig_string) => {
|
|
||||||
return Err(ReadIssuesError::FilenameError(orig_string))
|
|
||||||
}
|
|
||||||
};
|
|
||||||
let issue = crate::issue::Issue::new_from_dir(direntry.path().as_path())?;
|
let issue = crate::issue::Issue::new_from_dir(direntry.path().as_path())?;
|
||||||
issues.add_issue(uuid, issue);
|
issues.add_issue(issue);
|
||||||
} else if direntry.file_name() == "config.toml" {
|
} else if direntry.file_name() == "config.toml" {
|
||||||
issues.parse_config(direntry.path().as_path())?;
|
issues.parse_config(direntry.path().as_path())?;
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -93,29 +87,27 @@ mod tests {
|
||||||
let uuid = String::from("7792b063eef6d33e7da5dc1856750c149ba678c6");
|
let uuid = String::from("7792b063eef6d33e7da5dc1856750c149ba678c6");
|
||||||
let mut dir = std::path::PathBuf::from(issues_dir);
|
let mut dir = std::path::PathBuf::from(issues_dir);
|
||||||
dir.push(&uuid);
|
dir.push(&uuid);
|
||||||
expected.add_issue(
|
expected.add_issue(crate::issue::Issue {
|
||||||
uuid,
|
id: uuid,
|
||||||
crate::issue::Issue {
|
author: String::from("Sebastian Kuzminsky <seb@highlab.com>"),
|
||||||
author: String::from("Sebastian Kuzminsky <seb@highlab.com>"),
|
timestamp: chrono::DateTime::parse_from_rfc3339("2025-07-03T12:14:26-06:00")
|
||||||
timestamp: chrono::DateTime::parse_from_rfc3339("2025-07-03T12:14:26-06:00")
|
.unwrap()
|
||||||
.unwrap()
|
.with_timezone(&chrono::Local),
|
||||||
.with_timezone(&chrono::Local),
|
tags: Vec::<String>::new(),
|
||||||
tags: Vec::<String>::new(),
|
state: crate::issue::State::InProgress,
|
||||||
state: crate::issue::State::InProgress,
|
dependencies: None,
|
||||||
dependencies: None,
|
assignee: Some(String::from("beep boop")),
|
||||||
assignee: Some(String::from("beep boop")),
|
description: String::from("minimal"),
|
||||||
description: String::from("minimal"),
|
comments: Vec::<crate::comment::Comment>::new(),
|
||||||
comments: Vec::<crate::comment::Comment>::new(),
|
dir,
|
||||||
dir,
|
});
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
let uuid = String::from("3943fc5c173fdf41c0a22251593cd476d96e6c9f");
|
let uuid = String::from("3943fc5c173fdf41c0a22251593cd476d96e6c9f");
|
||||||
let mut dir = std::path::PathBuf::from(issues_dir);
|
let mut dir = std::path::PathBuf::from(issues_dir);
|
||||||
dir.push(&uuid);
|
dir.push(&uuid);
|
||||||
expected.add_issue(
|
expected.add_issue(
|
||||||
uuid,
|
|
||||||
crate::issue::Issue {
|
crate::issue::Issue {
|
||||||
|
id: uuid,
|
||||||
author: String::from("Sebastian Kuzminsky <seb@highlab.com>"),
|
author: String::from("Sebastian Kuzminsky <seb@highlab.com>"),
|
||||||
timestamp: chrono::DateTime::parse_from_rfc3339("2025-07-03T12:14:26-06:00")
|
timestamp: chrono::DateTime::parse_from_rfc3339("2025-07-03T12:14:26-06:00")
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
|
@ -146,22 +138,20 @@ mod tests {
|
||||||
let uuid = String::from("3fa5bfd93317ad25772680071d5ac3259cd2384f");
|
let uuid = String::from("3fa5bfd93317ad25772680071d5ac3259cd2384f");
|
||||||
let mut dir = std::path::PathBuf::from(issues_dir);
|
let mut dir = std::path::PathBuf::from(issues_dir);
|
||||||
dir.push(&uuid);
|
dir.push(&uuid);
|
||||||
expected.add_issue(
|
expected.add_issue(crate::issue::Issue {
|
||||||
uuid,
|
id: uuid,
|
||||||
crate::issue::Issue {
|
author: String::from("Sebastian Kuzminsky <seb@highlab.com>"),
|
||||||
author: String::from("Sebastian Kuzminsky <seb@highlab.com>"),
|
timestamp: chrono::DateTime::parse_from_rfc3339("2025-07-03T11:59:44-06:00")
|
||||||
timestamp: chrono::DateTime::parse_from_rfc3339("2025-07-03T11:59:44-06:00")
|
.unwrap()
|
||||||
.unwrap()
|
.with_timezone(&chrono::Local),
|
||||||
.with_timezone(&chrono::Local),
|
tags: Vec::<String>::new(),
|
||||||
tags: Vec::<String>::new(),
|
state: crate::issue::State::Done,
|
||||||
state: crate::issue::State::Done,
|
dependencies: None,
|
||||||
dependencies: None,
|
assignee: None,
|
||||||
assignee: None,
|
description: String::from("oh yeah we got titles"),
|
||||||
description: String::from("oh yeah we got titles"),
|
comments: Vec::<crate::comment::Comment>::new(),
|
||||||
comments: Vec::<crate::comment::Comment>::new(),
|
dir,
|
||||||
dir,
|
});
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
let uuid = String::from("dd79c8cfb8beeacd0460429944b4ecbe95a31561");
|
let uuid = String::from("dd79c8cfb8beeacd0460429944b4ecbe95a31561");
|
||||||
let mut dir = std::path::PathBuf::from(issues_dir);
|
let mut dir = std::path::PathBuf::from(issues_dir);
|
||||||
|
|
@ -181,8 +171,8 @@ mod tests {
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
expected.add_issue(
|
expected.add_issue(
|
||||||
uuid,
|
|
||||||
crate::issue::Issue {
|
crate::issue::Issue {
|
||||||
|
id: uuid,
|
||||||
author: String::from("Sebastian Kuzminsky <seb@highlab.com>"),
|
author: String::from("Sebastian Kuzminsky <seb@highlab.com>"),
|
||||||
timestamp: chrono::DateTime::parse_from_rfc3339("2025-07-03T11:59:44-06:00")
|
timestamp: chrono::DateTime::parse_from_rfc3339("2025-07-03T11:59:44-06:00")
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
|
@ -209,29 +199,27 @@ mod tests {
|
||||||
let uuid = String::from("3fa5bfd93317ad25772680071d5ac3259cd2384f");
|
let uuid = String::from("3fa5bfd93317ad25772680071d5ac3259cd2384f");
|
||||||
let mut dir = std::path::PathBuf::from(issues_dir);
|
let mut dir = std::path::PathBuf::from(issues_dir);
|
||||||
dir.push(&uuid);
|
dir.push(&uuid);
|
||||||
expected.add_issue(
|
expected.add_issue(crate::issue::Issue {
|
||||||
uuid,
|
id: uuid,
|
||||||
crate::issue::Issue {
|
author: String::from("sigil-03 <sigil@glyphs.tech>"),
|
||||||
author: String::from("sigil-03 <sigil@glyphs.tech>"),
|
timestamp: chrono::DateTime::parse_from_rfc3339("2025-07-05T13:55:49-06:00")
|
||||||
timestamp: chrono::DateTime::parse_from_rfc3339("2025-07-05T13:55:49-06:00")
|
.unwrap()
|
||||||
.unwrap()
|
.with_timezone(&chrono::Local),
|
||||||
.with_timezone(&chrono::Local),
|
tags: Vec::<String>::new(),
|
||||||
tags: Vec::<String>::new(),
|
state: crate::issue::State::Done,
|
||||||
state: crate::issue::State::Done,
|
dependencies: None,
|
||||||
dependencies: None,
|
assignee: None,
|
||||||
assignee: None,
|
description: String::from("oh yeah we got titles\n"),
|
||||||
description: String::from("oh yeah we got titles\n"),
|
comments: Vec::<crate::comment::Comment>::new(),
|
||||||
comments: Vec::<crate::comment::Comment>::new(),
|
dir,
|
||||||
dir,
|
});
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
let uuid = String::from("dd79c8cfb8beeacd0460429944b4ecbe95a31561");
|
let uuid = String::from("dd79c8cfb8beeacd0460429944b4ecbe95a31561");
|
||||||
let mut dir = std::path::PathBuf::from(issues_dir);
|
let mut dir = std::path::PathBuf::from(issues_dir);
|
||||||
dir.push(&uuid);
|
dir.push(&uuid);
|
||||||
expected.add_issue(
|
expected.add_issue(
|
||||||
uuid,
|
|
||||||
crate::issue::Issue {
|
crate::issue::Issue {
|
||||||
|
id: uuid,
|
||||||
author: String::from("sigil-03 <sigil@glyphs.tech>"),
|
author: String::from("sigil-03 <sigil@glyphs.tech>"),
|
||||||
timestamp: chrono::DateTime::parse_from_rfc3339("2025-07-05T13:55:49-06:00")
|
timestamp: chrono::DateTime::parse_from_rfc3339("2025-07-05T13:55:49-06:00")
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
|
@ -250,8 +238,8 @@ mod tests {
|
||||||
let mut dir = std::path::PathBuf::from(issues_dir);
|
let mut dir = std::path::PathBuf::from(issues_dir);
|
||||||
dir.push(&uuid);
|
dir.push(&uuid);
|
||||||
expected.add_issue(
|
expected.add_issue(
|
||||||
uuid,
|
|
||||||
crate::issue::Issue {
|
crate::issue::Issue {
|
||||||
|
id: uuid,
|
||||||
author: String::from("sigil-03 <sigil@glyphs.tech>"),
|
author: String::from("sigil-03 <sigil@glyphs.tech>"),
|
||||||
timestamp: chrono::DateTime::parse_from_rfc3339("2025-07-05T13:55:49-06:00")
|
timestamp: chrono::DateTime::parse_from_rfc3339("2025-07-05T13:55:49-06:00")
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue