Compare commits

..

No commits in common. "24a99d29577d1a23451dd666657c23ea35289503" and "6a1e438c9471f0be5d9137626c1158fbe7a47b9c" have entirely different histories.

5 changed files with 12 additions and 109 deletions

View file

@ -99,12 +99,6 @@ enum Commands {
issue_id: String,
done_time: Option<String>,
},
/// get or add a dependency to the issue
Depend {
issue_id: String,
dependency_id: Option<String>,
},
}
fn handle_command(
@ -516,43 +510,6 @@ fn handle_command(
},
};
}
Commands::Depend {
issue_id,
dependency_id,
} => match dependency_id {
Some(dep_id) => {
let ent_db = entomologist::database::make_issues_database(
issues_database_source,
entomologist::database::IssuesDatabaseAccess::ReadWrite,
)?;
let mut issues = entomologist::issues::Issues::new_from_dir(&ent_db.dir)?;
if issues.issues.contains_key(dep_id) {
if let Some(issue) = issues.issues.get_mut(issue_id) {
issue.add_dependency(dep_id.clone())?;
} else {
Err(anyhow::anyhow!("issue {} not found", issue_id))?;
};
} else {
Err(anyhow::anyhow!("dependency {} not found", dep_id))?;
};
}
None => {
let ent_db = entomologist::database::read_issues_database(issues_database_source)?;
let Some(issue) = ent_db.issues.get(issue_id) else {
Err(anyhow::anyhow!("issue {} not found", issue_id))?
};
println!("DEPENDENCIES:");
if let Some(list) = &issue.dependencies {
for dependency in list {
println!("{}", dependency);
}
} else {
println!("NONE");
}
}
},
}
Ok(())
@ -574,7 +531,7 @@ fn main() -> anyhow::Result<()> {
(Some(_), Some(_)) => {
return Err(anyhow::anyhow!(
"don't specify both `--issues-dir` and `--issues-branch`"
));
))
}
};

View file

@ -62,12 +62,6 @@ pub enum IssueError {
StdioIsNotTerminal,
#[error("Failed to parse issue ID")]
IdError,
#[error("Dependency not found")]
DepNotFound,
#[error("Dependency already exists")]
DepExists,
#[error("Self-dependency not allowed")]
DepSelf,
}
impl FromStr for State {
@ -134,8 +128,15 @@ impl Issue {
std::fs::read_to_string(direntry.path())?.trim(),
)?;
done_time = Some(raw_done_time.into());
} else if file_name == "dependencies" && direntry.metadata()?.is_dir() {
dependencies = Self::read_dependencies(&direntry.path())?;
} 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();
if deps.len() > 0 {
dependencies = Some(deps);
}
} else if file_name == "tags" {
let contents = std::fs::read_to_string(direntry.path())?;
tags = contents
@ -198,23 +199,6 @@ impl Issue {
Ok(())
}
fn read_dependencies(dir: &std::path::Path) -> Result<Option<Vec<IssueHandle>>, IssueError> {
let mut dependencies: Option<Vec<String>> = None;
for direntry in dir.read_dir()? {
if let Ok(direntry) = direntry {
match &mut dependencies {
Some(deps) => {
deps.push(direntry.file_name().into_string().unwrap());
}
None => {
dependencies = Some(vec![direntry.file_name().into_string().unwrap()]);
}
}
}
}
Ok(dependencies)
}
/// Add a new Comment to the Issue. Commits.
pub fn add_comment(
&mut self,
@ -423,46 +407,6 @@ impl Issue {
}
return false;
}
pub fn add_dependency(&mut self, dep: IssueHandle) -> Result<(), IssueError> {
if self.id == dep {
Err(IssueError::DepSelf)?;
}
match &mut self.dependencies {
Some(v) => v.push(dep.clone()),
None => self.dependencies = Some(vec![dep.clone()]),
}
let mut dir = std::path::PathBuf::from(&self.dir);
dir.push("dependencies");
if !dir.exists() {
std::fs::create_dir(&dir)?;
}
dir.push(dep.clone());
if !dir.exists() {
std::fs::File::create(&dir)?;
self.commit(&format!("add dep {} to issue {}", dep, self.id))?;
} else {
Err(IssueError::DepExists)?;
}
Ok(())
}
pub fn remove_dependency(&mut self, dep: IssueHandle) -> Result<(), IssueError> {
match &mut self.dependencies {
Some(v) => {
if let Some(i) = v.iter().position(|d| d == &dep) {
v.remove(i);
} else {
Err(IssueError::DepNotFound)?;
}
}
None => Err(IssueError::DepNotFound)?,
}
self.commit(&format!("remove dep {} from issue {}", dep, self.id))?;
Ok(())
}
}
// This is the internal/private API of Issue.

View file

@ -0,0 +1,2 @@
3fa5bfd93317ad25772680071d5ac3259cd2384f
dd79c8cfb8beeacd0460429944b4ecbe95a31561