Compare commits
4 commits
92adb554a5
...
a2c7ce34a3
| Author | SHA1 | Date | |
|---|---|---|---|
| a2c7ce34a3 | |||
| be362517fb | |||
| 431c67d43d | |||
| 7d9284bf91 |
7 changed files with 117 additions and 28 deletions
|
|
@ -9,6 +9,7 @@ log = ["dep:log", "dep:simple_logger"]
|
|||
|
||||
[dependencies]
|
||||
anyhow = "1.0.95"
|
||||
chrono = "0.4.41"
|
||||
clap = { version = "4.5.26", features = ["derive"] }
|
||||
log = { version = "0.4.27", optional = true }
|
||||
rand = "0.9.1"
|
||||
|
|
|
|||
|
|
@ -23,7 +23,11 @@ struct Args {
|
|||
#[derive(clap::Subcommand, Debug)]
|
||||
enum Commands {
|
||||
/// List issues.
|
||||
List,
|
||||
List {
|
||||
/// Filter string, describes issues to include in the list.
|
||||
#[arg(default_value_t = String::from("state=New,Backlog,Blocked,InProgress"))]
|
||||
filter: String,
|
||||
},
|
||||
|
||||
/// Create a new issue.
|
||||
New { description: Option<String> },
|
||||
|
|
@ -58,13 +62,16 @@ enum Commands {
|
|||
|
||||
fn handle_command(args: &Args, issues_dir: &std::path::Path) -> anyhow::Result<()> {
|
||||
match &args.command {
|
||||
Commands::List => {
|
||||
Commands::List { filter } => {
|
||||
let issues =
|
||||
entomologist::issues::Issues::new_from_dir(std::path::Path::new(issues_dir))?;
|
||||
let filter = entomologist::parse_filter(filter)?;
|
||||
for (uuid, issue) in issues.issues.iter() {
|
||||
if filter.include_states.contains(&issue.state) {
|
||||
println!("{} {} ({:?})", uuid, issue.title(), issue.state);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Commands::New {
|
||||
description: Some(description),
|
||||
|
|
@ -105,9 +112,10 @@ fn handle_command(args: &Args, issues_dir: &std::path::Path) -> anyhow::Result<(
|
|||
}
|
||||
println!("");
|
||||
println!("{}", issue.description);
|
||||
for (uuid, comment) in issue.comments.iter() {
|
||||
for comment in &issue.comments {
|
||||
println!("");
|
||||
println!("comment: {}", uuid);
|
||||
println!("comment: {}", comment.uuid);
|
||||
println!("timestamp: {}", comment.timestamp);
|
||||
println!("{}", comment.description);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@ use std::io::Write;
|
|||
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub struct Comment {
|
||||
pub uuid: String,
|
||||
pub timestamp: chrono::DateTime<chrono::Local>,
|
||||
pub description: String,
|
||||
|
||||
/// This is the directory that the comment lives in. Only used
|
||||
|
|
@ -39,12 +41,16 @@ impl Comment {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
if description == None {
|
||||
return Err(CommentError::CommentParseError);
|
||||
}
|
||||
|
||||
let timestamp = crate::git::git_log_oldest_timestamp(comment_dir)?;
|
||||
let dir = std::path::PathBuf::from(comment_dir);
|
||||
|
||||
Ok(Self {
|
||||
uuid: String::from(dir.file_name().unwrap().to_string_lossy()),
|
||||
timestamp,
|
||||
description: description.unwrap(),
|
||||
dir: std::path::PathBuf::from(comment_dir),
|
||||
})
|
||||
|
|
@ -95,8 +101,11 @@ mod tests {
|
|||
std::path::Path::new("test/0001/dd79c8cfb8beeacd0460429944b4ecbe95a31561/comments/9055dac36045fe36545bed7ae7b49347");
|
||||
let comment = Comment::new_from_dir(comment_dir).unwrap();
|
||||
let expected = Comment {
|
||||
uuid: String::from("9055dac36045fe36545bed7ae7b49347"),
|
||||
timestamp: chrono::DateTime::parse_from_rfc3339("2025-07-07T15:26:26-06:00")
|
||||
.unwrap()
|
||||
.with_timezone(&chrono::Local),
|
||||
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);
|
||||
|
|
|
|||
30
src/git.rs
30
src/git.rs
|
|
@ -4,6 +4,8 @@ use std::io::Write;
|
|||
pub enum GitError {
|
||||
#[error(transparent)]
|
||||
StdIoError(#[from] std::io::Error),
|
||||
#[error(transparent)]
|
||||
ParseIntError(#[from] std::num::ParseIntError),
|
||||
#[error("Oops, something went wrong")]
|
||||
Oops,
|
||||
}
|
||||
|
|
@ -180,6 +182,34 @@ pub fn sync(dir: &std::path::Path, remote: &str, branch: &str) -> Result<(), Git
|
|||
Ok(())
|
||||
}
|
||||
|
||||
pub fn git_log_oldest_timestamp(
|
||||
path: &std::path::Path,
|
||||
) -> Result<chrono::DateTime<chrono::Local>, GitError> {
|
||||
let mut git_dir = std::path::PathBuf::from(path);
|
||||
git_dir.pop();
|
||||
let result = std::process::Command::new("git")
|
||||
.args([
|
||||
"log",
|
||||
"--pretty=format:%at",
|
||||
"--",
|
||||
&path.file_name().unwrap().to_string_lossy(),
|
||||
])
|
||||
.current_dir(&git_dir)
|
||||
.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(GitError::Oops);
|
||||
}
|
||||
let timestamp_str = std::str::from_utf8(&result.stdout).unwrap();
|
||||
let timestamp_last = timestamp_str.split("\n").last().unwrap();
|
||||
let timestamp_i64 = timestamp_last.parse::<i64>()?;
|
||||
let timestamp = chrono::DateTime::from_timestamp(timestamp_i64, 0)
|
||||
.unwrap()
|
||||
.with_timezone(&chrono::Local);
|
||||
Ok(timestamp)
|
||||
}
|
||||
|
||||
pub fn create_orphan_branch(branch: &str) -> Result<(), GitError> {
|
||||
{
|
||||
let tmp_worktree = tempfile::tempdir().unwrap();
|
||||
|
|
|
|||
27
src/issue.rs
27
src/issue.rs
|
|
@ -5,7 +5,7 @@ use std::str::FromStr;
|
|||
#[cfg(feature = "log")]
|
||||
use log::debug;
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, serde::Deserialize)]
|
||||
#[derive(Clone, Debug, Eq, Hash, PartialEq, serde::Deserialize)]
|
||||
/// These are the states an issue can be in.
|
||||
pub enum State {
|
||||
New,
|
||||
|
|
@ -23,7 +23,7 @@ pub struct Issue {
|
|||
pub description: String,
|
||||
pub state: State,
|
||||
pub dependencies: Option<Vec<IssueHandle>>,
|
||||
pub comments: std::collections::HashMap<String, crate::comment::Comment>,
|
||||
pub comments: Vec<crate::comment::Comment>,
|
||||
|
||||
/// This is the directory that the issue lives in. Only used
|
||||
/// internally by the entomologist library.
|
||||
|
|
@ -38,6 +38,8 @@ pub enum IssueError {
|
|||
CommentError(#[from] crate::comment::CommentError),
|
||||
#[error("Failed to parse issue")]
|
||||
IssueParseError,
|
||||
#[error("Failed to parse state")]
|
||||
StateParseError,
|
||||
#[error("Failed to run git")]
|
||||
GitError(#[from] crate::git::GitError),
|
||||
#[error("Failed to run editor")]
|
||||
|
|
@ -61,7 +63,7 @@ impl FromStr for State {
|
|||
} else if s == "wontdo" {
|
||||
Ok(State::WontDo)
|
||||
} else {
|
||||
Err(IssueError::IssueParseError)
|
||||
Err(IssueError::StateParseError)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -85,7 +87,7 @@ impl Issue {
|
|||
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;
|
||||
let mut comments = std::collections::HashMap::<String, crate::comment::Comment>::new();
|
||||
let mut comments = Vec::<crate::comment::Comment>::new();
|
||||
|
||||
for direntry in dir.read_dir()? {
|
||||
if let Ok(direntry) = direntry {
|
||||
|
|
@ -127,16 +129,16 @@ impl Issue {
|
|||
}
|
||||
|
||||
fn read_comments(
|
||||
comments: &mut std::collections::HashMap<String, crate::comment::Comment>,
|
||||
comments: &mut Vec<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);
|
||||
comments.push(comment);
|
||||
}
|
||||
}
|
||||
comments.sort_by(|a, b| a.timestamp.cmp(&b.timestamp));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
@ -148,10 +150,13 @@ impl Issue {
|
|||
}
|
||||
|
||||
let rnd: u128 = rand::random();
|
||||
dir.push(&format!("{:032x}", rnd));
|
||||
let uuid = format!("{:032x}", rnd);
|
||||
dir.push(&uuid);
|
||||
std::fs::create_dir(&dir)?;
|
||||
|
||||
Ok(crate::comment::Comment {
|
||||
uuid,
|
||||
timestamp: chrono::Local::now(),
|
||||
description: String::from(""), // FIXME
|
||||
dir,
|
||||
})
|
||||
|
|
@ -166,7 +171,7 @@ impl Issue {
|
|||
description: String::from(""), // FIXME: kind of bogus to use the empty string as None
|
||||
state: State::New,
|
||||
dependencies: None,
|
||||
comments: std::collections::HashMap::<String, crate::comment::Comment>::new(),
|
||||
comments: Vec::<crate::comment::Comment>::new(),
|
||||
dir: issue_dir,
|
||||
})
|
||||
}
|
||||
|
|
@ -242,7 +247,7 @@ 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"),
|
||||
state: State::New,
|
||||
dependencies: None,
|
||||
comments: std::collections::HashMap::<String, crate::comment::Comment>::new(),
|
||||
comments: Vec::<crate::comment::Comment>::new(),
|
||||
dir: std::path::PathBuf::from(issue_dir),
|
||||
};
|
||||
assert_eq!(issue, expected);
|
||||
|
|
@ -256,7 +261,7 @@ mod tests {
|
|||
description: String::from("minimal"),
|
||||
state: State::InProgress,
|
||||
dependencies: None,
|
||||
comments: std::collections::HashMap::<String, crate::comment::Comment>::new(),
|
||||
comments: Vec::<crate::comment::Comment>::new(),
|
||||
dir: std::path::PathBuf::from(issue_dir),
|
||||
};
|
||||
assert_eq!(issue, expected);
|
||||
|
|
|
|||
|
|
@ -99,7 +99,7 @@ mod tests {
|
|||
description: String::from("minimal"),
|
||||
state: crate::issue::State::InProgress,
|
||||
dependencies: None,
|
||||
comments: std::collections::HashMap::<String, crate::comment::Comment>::new(),
|
||||
comments: Vec::<crate::comment::Comment>::new(),
|
||||
dir,
|
||||
},
|
||||
);
|
||||
|
|
@ -113,7 +113,7 @@ 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"),
|
||||
state: crate::issue::State::New,
|
||||
dependencies: None,
|
||||
comments: std::collections::HashMap::<String, crate::comment::Comment>::new(),
|
||||
comments: Vec::<crate::comment::Comment>::new(),
|
||||
dir,
|
||||
}
|
||||
);
|
||||
|
|
@ -136,7 +136,7 @@ mod tests {
|
|||
description: String::from("oh yeah we got titles"),
|
||||
state: crate::issue::State::Done,
|
||||
dependencies: None,
|
||||
comments: std::collections::HashMap::<String, crate::comment::Comment>::new(),
|
||||
comments: Vec::<crate::comment::Comment>::new(),
|
||||
dir,
|
||||
},
|
||||
);
|
||||
|
|
@ -148,12 +148,12 @@ mod tests {
|
|||
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),
|
||||
let mut expected_comments = Vec::<crate::comment::Comment>::new();
|
||||
expected_comments.push(
|
||||
crate::comment::Comment {
|
||||
uuid: comment_uuid,
|
||||
description: String::from("This is a comment on issue dd79c8cfb8beeacd0460429944b4ecbe95a31561\n\nIt has multiple lines\n"),
|
||||
timestamp: chrono::DateTime::parse_from_rfc3339("2025-07-07T15:26:26-06:00").unwrap().with_timezone(&chrono::Local),
|
||||
dir: std::path::PathBuf::from(comment_dir),
|
||||
}
|
||||
);
|
||||
|
|
@ -186,7 +186,7 @@ mod tests {
|
|||
description: String::from("oh yeah we got titles\n"),
|
||||
state: crate::issue::State::Done,
|
||||
dependencies: None,
|
||||
comments: std::collections::HashMap::<String, crate::comment::Comment>::new(),
|
||||
comments: Vec::<crate::comment::Comment>::new(),
|
||||
dir,
|
||||
},
|
||||
);
|
||||
|
|
@ -200,7 +200,7 @@ 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"),
|
||||
state: crate::issue::State::WontDo,
|
||||
dependencies: None,
|
||||
comments: std::collections::HashMap::<String, crate::comment::Comment>::new(),
|
||||
comments: Vec::<crate::comment::Comment>::new(),
|
||||
dir,
|
||||
},
|
||||
);
|
||||
|
|
@ -217,7 +217,7 @@ mod tests {
|
|||
crate::issue::IssueHandle::from("3fa5bfd93317ad25772680071d5ac3259cd2384f"),
|
||||
crate::issue::IssueHandle::from("dd79c8cfb8beeacd0460429944b4ecbe95a31561"),
|
||||
]),
|
||||
comments: std::collections::HashMap::<String, crate::comment::Comment>::new(),
|
||||
comments: Vec::<crate::comment::Comment>::new(),
|
||||
dir,
|
||||
},
|
||||
);
|
||||
|
|
|
|||
36
src/lib.rs
36
src/lib.rs
|
|
@ -1,4 +1,40 @@
|
|||
use std::str::FromStr;
|
||||
|
||||
pub mod comment;
|
||||
pub mod git;
|
||||
pub mod issue;
|
||||
pub mod issues;
|
||||
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
pub enum ParseFilterError {
|
||||
#[error("Failed to parse filter")]
|
||||
ParseError,
|
||||
#[error(transparent)]
|
||||
IssueParseError(#[from] crate::issue::IssueError),
|
||||
}
|
||||
|
||||
// FIXME: It's easy to imagine a full dsl for filtering issues, for now
|
||||
// i'm starting with obvious easy things. Chumsky looks appealing but
|
||||
// more research is needed.
|
||||
#[derive(Debug)]
|
||||
pub struct Filter {
|
||||
pub include_states: std::collections::HashSet<crate::issue::State>,
|
||||
}
|
||||
|
||||
// Parses a filter description matching "state=STATE[,STATE*]"
|
||||
pub fn parse_filter(filter_str: &str) -> Result<Filter, ParseFilterError> {
|
||||
let tokens: Vec<&str> = filter_str.split("=").collect();
|
||||
if tokens.len() != 2 {
|
||||
return Err(ParseFilterError::ParseError);
|
||||
}
|
||||
if tokens[0] != "state" {
|
||||
return Err(ParseFilterError::ParseError);
|
||||
}
|
||||
|
||||
let mut include_states = std::collections::HashSet::<crate::issue::State>::new();
|
||||
for s in tokens[1].split(",") {
|
||||
include_states.insert(crate::issue::State::from_str(s)?);
|
||||
}
|
||||
|
||||
Ok(Filter { include_states })
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue