Compare commits
No commits in common. "8ac4ca4c543ccddc15aef154601f753df5f51c42" and "5df03337d9e933f884b2df4ba9922a512b2e2d3e" have entirely different histories.
8ac4ca4c54
...
5df03337d9
6 changed files with 0 additions and 202 deletions
|
|
@ -39,12 +39,6 @@ enum Commands {
|
||||||
issue_id: String,
|
issue_id: String,
|
||||||
new_state: Option<State>,
|
new_state: Option<State>,
|
||||||
},
|
},
|
||||||
|
|
||||||
/// Create a new comment on an issue.
|
|
||||||
Comment {
|
|
||||||
issue_id: String,
|
|
||||||
description: Option<String>,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handle_command(args: &Args, issues_dir: &std::path::Path) -> anyhow::Result<()> {
|
fn handle_command(args: &Args, issues_dir: &std::path::Path) -> anyhow::Result<()> {
|
||||||
|
|
@ -96,11 +90,6 @@ fn handle_command(args: &Args, issues_dir: &std::path::Path) -> anyhow::Result<(
|
||||||
}
|
}
|
||||||
println!("");
|
println!("");
|
||||||
println!("{}", issue.description);
|
println!("{}", issue.description);
|
||||||
for (uuid, comment) in issue.comments.iter() {
|
|
||||||
println!("");
|
|
||||||
println!("comment: {}", uuid);
|
|
||||||
println!("{}", comment.description);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
return Err(anyhow::anyhow!("issue {} not found", issue_id));
|
return Err(anyhow::anyhow!("issue {} not found", issue_id));
|
||||||
|
|
@ -134,27 +123,6 @@ fn handle_command(args: &Args, issues_dir: &std::path::Path) -> anyhow::Result<(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Commands::Comment {
|
|
||||||
issue_id,
|
|
||||||
description,
|
|
||||||
} => {
|
|
||||||
let mut issues =
|
|
||||||
entomologist::issues::Issues::new_from_dir(std::path::Path::new(issues_dir))?;
|
|
||||||
let Some(issue) = issues.get_mut_issue(issue_id) else {
|
|
||||||
return Err(anyhow::anyhow!("issue {} not found", issue_id));
|
|
||||||
};
|
|
||||||
println!("found issue {}", issue.title());
|
|
||||||
let mut comment = issue.new_comment()?;
|
|
||||||
match description {
|
|
||||||
Some(description) => {
|
|
||||||
comment.set_description(description)?;
|
|
||||||
}
|
|
||||||
None => {
|
|
||||||
comment.edit_description()?;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
||||||
104
src/comment.rs
104
src/comment.rs
|
|
@ -1,104 +0,0 @@
|
||||||
use std::io::Write;
|
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
|
||||||
pub struct Comment {
|
|
||||||
pub description: String,
|
|
||||||
|
|
||||||
/// This is the directory that the comment lives in. Only used
|
|
||||||
/// internally by the entomologist library.
|
|
||||||
pub dir: std::path::PathBuf,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, thiserror::Error)]
|
|
||||||
pub enum CommentError {
|
|
||||||
#[error(transparent)]
|
|
||||||
StdIoError(#[from] std::io::Error),
|
|
||||||
#[error("Failed to parse comment")]
|
|
||||||
CommentParseError,
|
|
||||||
#[error("Failed to run git")]
|
|
||||||
GitError(#[from] crate::git::GitError),
|
|
||||||
#[error("Failed to run editor")]
|
|
||||||
EditorError,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Comment {
|
|
||||||
pub fn new_from_dir(comment_dir: &std::path::Path) -> Result<Self, CommentError> {
|
|
||||||
let mut description: Option<String> = None;
|
|
||||||
|
|
||||||
for direntry in comment_dir.read_dir()? {
|
|
||||||
if let Ok(direntry) = direntry {
|
|
||||||
let file_name = direntry.file_name();
|
|
||||||
if file_name == "description" {
|
|
||||||
description = Some(std::fs::read_to_string(direntry.path())?);
|
|
||||||
} else {
|
|
||||||
#[cfg(feature = "log")]
|
|
||||||
debug!(
|
|
||||||
"ignoring unknown file in comment directory: {:?}",
|
|
||||||
file_name
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if description == None {
|
|
||||||
return Err(CommentError::CommentParseError);
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(Self {
|
|
||||||
description: description.unwrap(),
|
|
||||||
dir: std::path::PathBuf::from(comment_dir),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn set_description(&mut self, description: &str) -> Result<(), CommentError> {
|
|
||||||
self.description = String::from(description);
|
|
||||||
let mut description_filename = std::path::PathBuf::from(&self.dir);
|
|
||||||
description_filename.push("description");
|
|
||||||
let mut description_file = std::fs::File::create(&description_filename)?;
|
|
||||||
write!(description_file, "{}", description)?;
|
|
||||||
crate::git::git_commit_file(&description_filename)?;
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn read_description(&mut self) -> Result<(), CommentError> {
|
|
||||||
let mut description_filename = std::path::PathBuf::from(&self.dir);
|
|
||||||
description_filename.push("description");
|
|
||||||
self.description = std::fs::read_to_string(description_filename)?;
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn edit_description(&mut self) -> Result<(), CommentError> {
|
|
||||||
let mut description_filename = std::path::PathBuf::from(&self.dir);
|
|
||||||
description_filename.push("description");
|
|
||||||
let result = std::process::Command::new("vi")
|
|
||||||
.arg(&description_filename.as_mut_os_str())
|
|
||||||
.spawn()?
|
|
||||||
.wait_with_output()?;
|
|
||||||
if !result.status.success() {
|
|
||||||
println!("stdout: {}", std::str::from_utf8(&result.stdout).unwrap());
|
|
||||||
println!("stderr: {}", std::str::from_utf8(&result.stderr).unwrap());
|
|
||||||
return Err(CommentError::EditorError);
|
|
||||||
}
|
|
||||||
crate::git::git_commit_file(&description_filename)?;
|
|
||||||
self.read_description()?;
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
use super::*;
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn read_comment_0() {
|
|
||||||
let comment_dir =
|
|
||||||
std::path::Path::new("test/0001/dd79c8cfb8beeacd0460429944b4ecbe95a31561/comments/9055dac36045fe36545bed7ae7b49347");
|
|
||||||
let comment = Comment::new_from_dir(comment_dir).unwrap();
|
|
||||||
let expected = Comment {
|
|
||||||
description: String::from("This is a comment on issue dd79c8cfb8beeacd0460429944b4ecbe95a31561\n\nIt has multiple lines\n"),
|
|
||||||
|
|
||||||
dir: std::path::PathBuf::from(comment_dir),
|
|
||||||
};
|
|
||||||
assert_eq!(comment, expected);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
42
src/issue.rs
42
src/issue.rs
|
|
@ -23,7 +23,6 @@ pub struct Issue {
|
||||||
pub description: String,
|
pub description: String,
|
||||||
pub state: State,
|
pub state: State,
|
||||||
pub dependencies: Option<Vec<IssueHandle>>,
|
pub dependencies: Option<Vec<IssueHandle>>,
|
||||||
pub comments: std::collections::HashMap<String, crate::comment::Comment>,
|
|
||||||
|
|
||||||
/// This is the directory that the issue lives in. Only used
|
/// This is the directory that the issue lives in. Only used
|
||||||
/// internally by the entomologist library.
|
/// internally by the entomologist library.
|
||||||
|
|
@ -34,8 +33,6 @@ pub struct Issue {
|
||||||
pub enum IssueError {
|
pub enum IssueError {
|
||||||
#[error(transparent)]
|
#[error(transparent)]
|
||||||
StdIoError(#[from] std::io::Error),
|
StdIoError(#[from] std::io::Error),
|
||||||
#[error(transparent)]
|
|
||||||
CommentError(#[from] crate::comment::CommentError),
|
|
||||||
#[error("Failed to parse issue")]
|
#[error("Failed to parse issue")]
|
||||||
IssueParseError,
|
IssueParseError,
|
||||||
#[error("Failed to run git")]
|
#[error("Failed to run git")]
|
||||||
|
|
@ -86,7 +83,6 @@ impl Issue {
|
||||||
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;
|
||||||
let mut comments = std::collections::HashMap::<String, crate::comment::Comment>::new();
|
|
||||||
|
|
||||||
for direntry in dir.read_dir()? {
|
for direntry in dir.read_dir()? {
|
||||||
if let Ok(direntry) = direntry {
|
if let Ok(direntry) = direntry {
|
||||||
|
|
@ -105,8 +101,6 @@ impl Issue {
|
||||||
if deps.len() > 0 {
|
if deps.len() > 0 {
|
||||||
dependencies = Some(deps);
|
dependencies = Some(deps);
|
||||||
}
|
}
|
||||||
} else if file_name == "comments" && direntry.metadata()?.is_dir() {
|
|
||||||
Self::read_comments(&mut comments, &direntry.path())?;
|
|
||||||
} else {
|
} else {
|
||||||
#[cfg(feature = "log")]
|
#[cfg(feature = "log")]
|
||||||
debug!("ignoring unknown file in issue directory: {:?}", file_name);
|
debug!("ignoring unknown file in issue directory: {:?}", file_name);
|
||||||
|
|
@ -122,43 +116,10 @@ impl Issue {
|
||||||
description: description.unwrap(),
|
description: description.unwrap(),
|
||||||
state: state,
|
state: state,
|
||||||
dependencies,
|
dependencies,
|
||||||
comments,
|
|
||||||
dir: std::path::PathBuf::from(dir),
|
dir: std::path::PathBuf::from(dir),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn read_comments(
|
|
||||||
comments: &mut std::collections::HashMap<String, crate::comment::Comment>,
|
|
||||||
dir: &std::path::Path,
|
|
||||||
) -> Result<(), IssueError> {
|
|
||||||
for direntry in dir.read_dir()? {
|
|
||||||
if let Ok(direntry) = direntry {
|
|
||||||
let uuid = direntry.file_name();
|
|
||||||
let comment = crate::comment::Comment::new_from_dir(&direntry.path())?;
|
|
||||||
comments.insert(String::from(uuid.to_string_lossy()), comment);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn new_comment(&mut self) -> Result<crate::comment::Comment, IssueError> {
|
|
||||||
let mut dir = std::path::PathBuf::from(&self.dir);
|
|
||||||
dir.push("comments");
|
|
||||||
if !dir.exists() {
|
|
||||||
println!("creating {}", dir.to_string_lossy());
|
|
||||||
std::fs::create_dir(&dir)?;
|
|
||||||
}
|
|
||||||
|
|
||||||
let rnd: u128 = rand::random();
|
|
||||||
dir.push(&format!("{:032x}", rnd));
|
|
||||||
std::fs::create_dir(&dir)?;
|
|
||||||
|
|
||||||
Ok(crate::comment::Comment {
|
|
||||||
description: String::from(""), // FIXME
|
|
||||||
dir,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn new(dir: &std::path::Path) -> Result<Self, IssueError> {
|
pub fn new(dir: &std::path::Path) -> Result<Self, IssueError> {
|
||||||
let mut issue_dir = std::path::PathBuf::from(dir);
|
let mut issue_dir = std::path::PathBuf::from(dir);
|
||||||
let rnd: u128 = rand::random();
|
let rnd: u128 = rand::random();
|
||||||
|
|
@ -168,7 +129,6 @@ impl Issue {
|
||||||
description: String::from(""), // FIXME: kind of bogus to use the empty string as None
|
description: String::from(""), // FIXME: kind of bogus to use the empty string as None
|
||||||
state: State::New,
|
state: State::New,
|
||||||
dependencies: None,
|
dependencies: None,
|
||||||
comments: std::collections::HashMap::<String, crate::comment::Comment>::new(),
|
|
||||||
dir: issue_dir,
|
dir: issue_dir,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
@ -244,7 +204,6 @@ mod tests {
|
||||||
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"),
|
||||||
state: State::New,
|
state: State::New,
|
||||||
dependencies: None,
|
dependencies: None,
|
||||||
comments: std::collections::HashMap::<String, crate::comment::Comment>::new(),
|
|
||||||
dir: std::path::PathBuf::from(issue_dir),
|
dir: std::path::PathBuf::from(issue_dir),
|
||||||
};
|
};
|
||||||
assert_eq!(issue, expected);
|
assert_eq!(issue, expected);
|
||||||
|
|
@ -258,7 +217,6 @@ mod tests {
|
||||||
description: String::from("minimal"),
|
description: String::from("minimal"),
|
||||||
state: State::InProgress,
|
state: State::InProgress,
|
||||||
dependencies: None,
|
dependencies: None,
|
||||||
comments: std::collections::HashMap::<String, crate::comment::Comment>::new(),
|
|
||||||
dir: std::path::PathBuf::from(issue_dir),
|
dir: std::path::PathBuf::from(issue_dir),
|
||||||
};
|
};
|
||||||
assert_eq!(issue, expected);
|
assert_eq!(issue, expected);
|
||||||
|
|
|
||||||
|
|
@ -99,7 +99,6 @@ mod tests {
|
||||||
description: String::from("minimal"),
|
description: String::from("minimal"),
|
||||||
state: crate::issue::State::InProgress,
|
state: crate::issue::State::InProgress,
|
||||||
dependencies: None,
|
dependencies: None,
|
||||||
comments: std::collections::HashMap::<String, crate::comment::Comment>::new(),
|
|
||||||
dir,
|
dir,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
@ -113,7 +112,6 @@ mod tests {
|
||||||
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"),
|
||||||
state: crate::issue::State::New,
|
state: crate::issue::State::New,
|
||||||
dependencies: None,
|
dependencies: None,
|
||||||
comments: std::collections::HashMap::<String, crate::comment::Comment>::new(),
|
|
||||||
dir,
|
dir,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
@ -136,7 +134,6 @@ mod tests {
|
||||||
description: String::from("oh yeah we got titles"),
|
description: String::from("oh yeah we got titles"),
|
||||||
state: crate::issue::State::Done,
|
state: crate::issue::State::Done,
|
||||||
dependencies: None,
|
dependencies: None,
|
||||||
comments: std::collections::HashMap::<String, crate::comment::Comment>::new(),
|
|
||||||
dir,
|
dir,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
@ -144,26 +141,12 @@ mod tests {
|
||||||
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);
|
||||||
let mut comment_dir = dir.clone();
|
|
||||||
let comment_uuid = String::from("9055dac36045fe36545bed7ae7b49347");
|
|
||||||
comment_dir.push("comments");
|
|
||||||
comment_dir.push(&comment_uuid);
|
|
||||||
let mut expected_comments =
|
|
||||||
std::collections::HashMap::<String, crate::comment::Comment>::new();
|
|
||||||
expected_comments.insert(
|
|
||||||
String::from(&comment_uuid),
|
|
||||||
crate::comment::Comment {
|
|
||||||
description: String::from("This is a comment on issue dd79c8cfb8beeacd0460429944b4ecbe95a31561\n\nIt has multiple lines\n"),
|
|
||||||
dir: std::path::PathBuf::from(comment_dir),
|
|
||||||
}
|
|
||||||
);
|
|
||||||
expected.add_issue(
|
expected.add_issue(
|
||||||
uuid,
|
uuid,
|
||||||
crate::issue::Issue {
|
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"),
|
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,
|
state: crate::issue::State::WontDo,
|
||||||
dependencies: None,
|
dependencies: None,
|
||||||
comments: expected_comments,
|
|
||||||
dir,
|
dir,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
@ -186,7 +169,6 @@ mod tests {
|
||||||
description: String::from("oh yeah we got titles\n"),
|
description: String::from("oh yeah we got titles\n"),
|
||||||
state: crate::issue::State::Done,
|
state: crate::issue::State::Done,
|
||||||
dependencies: None,
|
dependencies: None,
|
||||||
comments: std::collections::HashMap::<String, crate::comment::Comment>::new(),
|
|
||||||
dir,
|
dir,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
@ -200,7 +182,6 @@ mod tests {
|
||||||
description: String::from("issues out the wazoo\n\nLots 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,
|
state: crate::issue::State::WontDo,
|
||||||
dependencies: None,
|
dependencies: None,
|
||||||
comments: std::collections::HashMap::<String, crate::comment::Comment>::new(),
|
|
||||||
dir,
|
dir,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
@ -217,7 +198,6 @@ mod tests {
|
||||||
crate::issue::IssueHandle::from("3fa5bfd93317ad25772680071d5ac3259cd2384f"),
|
crate::issue::IssueHandle::from("3fa5bfd93317ad25772680071d5ac3259cd2384f"),
|
||||||
crate::issue::IssueHandle::from("dd79c8cfb8beeacd0460429944b4ecbe95a31561"),
|
crate::issue::IssueHandle::from("dd79c8cfb8beeacd0460429944b4ecbe95a31561"),
|
||||||
]),
|
]),
|
||||||
comments: std::collections::HashMap::<String, crate::comment::Comment>::new(),
|
|
||||||
dir,
|
dir,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
pub mod comment;
|
|
||||||
pub mod git;
|
pub mod git;
|
||||||
pub mod issue;
|
pub mod issue;
|
||||||
pub mod issues;
|
pub mod issues;
|
||||||
|
|
|
||||||
|
|
@ -1,3 +0,0 @@
|
||||||
This is a comment on issue dd79c8cfb8beeacd0460429944b4ecbe95a31561
|
|
||||||
|
|
||||||
It has multiple lines
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue