add ent assign ISSUE PERSON
This commit is contained in:
parent
645062d10c
commit
d21b811bee
2 changed files with 46 additions and 0 deletions
|
|
@ -58,6 +58,12 @@ enum Commands {
|
||||||
#[arg(default_value_t = String::from("origin"))]
|
#[arg(default_value_t = String::from("origin"))]
|
||||||
remote: String,
|
remote: String,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/// Get or set the Assignee field of an Issue.
|
||||||
|
Assign {
|
||||||
|
issue_id: String,
|
||||||
|
new_assignee: 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<()> {
|
||||||
|
|
@ -234,6 +240,37 @@ fn handle_command(args: &Args, issues_dir: &std::path::Path) -> anyhow::Result<(
|
||||||
entomologist::git::sync(issues_dir, remote, branch)?;
|
entomologist::git::sync(issues_dir, remote, branch)?;
|
||||||
println!("synced {:?} with {:?}", branch, remote);
|
println!("synced {:?} with {:?}", branch, remote);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Commands::Assign {
|
||||||
|
issue_id,
|
||||||
|
new_assignee,
|
||||||
|
} => {
|
||||||
|
let mut issues =
|
||||||
|
entomologist::issues::Issues::new_from_dir(std::path::Path::new(issues_dir))?;
|
||||||
|
let Some(issue) = issues.issues.get_mut(issue_id) else {
|
||||||
|
return Err(anyhow::anyhow!("issue {} not found", issue_id));
|
||||||
|
};
|
||||||
|
match (&issue.assignee, new_assignee) {
|
||||||
|
(Some(old_assignee), Some(new_assignee)) => {
|
||||||
|
println!("issue: {}", issue_id);
|
||||||
|
println!("assignee: {} -> {}", old_assignee, new_assignee);
|
||||||
|
issue.set_assignee(new_assignee)?;
|
||||||
|
}
|
||||||
|
(Some(old_assignee), None) => {
|
||||||
|
println!("issue: {}", issue_id);
|
||||||
|
println!("assignee: {}", old_assignee);
|
||||||
|
}
|
||||||
|
(None, Some(new_assignee)) => {
|
||||||
|
println!("issue: {}", issue_id);
|
||||||
|
println!("assignee: None -> {}", new_assignee);
|
||||||
|
issue.set_assignee(new_assignee)?;
|
||||||
|
}
|
||||||
|
(None, None) => {
|
||||||
|
println!("issue: {}", issue_id);
|
||||||
|
println!("assignee: None");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
||||||
|
|
@ -251,6 +251,15 @@ impl Issue {
|
||||||
self.state = State::from_str(state_string.trim())?;
|
self.state = State::from_str(state_string.trim())?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn set_assignee(&mut self, new_assignee: &str) -> Result<(), IssueError> {
|
||||||
|
let mut assignee_filename = std::path::PathBuf::from(&self.dir);
|
||||||
|
assignee_filename.push("assignee");
|
||||||
|
let mut assignee_file = std::fs::File::create(&assignee_filename)?;
|
||||||
|
write!(assignee_file, "{}", new_assignee)?;
|
||||||
|
crate::git::git_commit_file(&assignee_filename)?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue