Issue: make a helper function to commit an Issue
This improves code reuse and streamlines the code a bit.
This commit is contained in:
parent
e0d9d45a6a
commit
5e5508a2ee
1 changed files with 31 additions and 42 deletions
45
src/issue.rs
45
src/issue.rs
|
|
@ -243,8 +243,7 @@ impl Issue {
|
||||||
None => issue.edit_description_file()?,
|
None => issue.edit_description_file()?,
|
||||||
};
|
};
|
||||||
|
|
||||||
crate::git::add(&issue_dir)?;
|
issue.commit(&format!("create new issue {}", issue_id))?;
|
||||||
crate::git::commit(&issue_dir, &format!("create new issue {}", issue_id))?;
|
|
||||||
|
|
||||||
Ok(issue)
|
Ok(issue)
|
||||||
}
|
}
|
||||||
|
|
@ -253,21 +252,15 @@ impl Issue {
|
||||||
pub fn edit_description(&mut self) -> Result<(), IssueError> {
|
pub fn edit_description(&mut self) -> Result<(), IssueError> {
|
||||||
self.edit_description_file()?;
|
self.edit_description_file()?;
|
||||||
let description_filename = self.description_filename();
|
let description_filename = self.description_filename();
|
||||||
crate::git::add(&description_filename)?;
|
self.commit(&format!(
|
||||||
if crate::git::worktree_is_dirty(&self.dir.to_string_lossy())? {
|
|
||||||
crate::git::commit(
|
|
||||||
&description_filename.parent().unwrap(),
|
|
||||||
&format!(
|
|
||||||
"edit description of issue {}",
|
"edit description of issue {}",
|
||||||
description_filename
|
description_filename
|
||||||
.parent()
|
.parent()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.file_name()
|
.file_name()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.to_string_lossy()
|
.to_string_lossy(),
|
||||||
),
|
))?;
|
||||||
)?;
|
|
||||||
}
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -286,18 +279,12 @@ impl Issue {
|
||||||
state_filename.push("state");
|
state_filename.push("state");
|
||||||
let mut state_file = std::fs::File::create(&state_filename)?;
|
let mut state_file = std::fs::File::create(&state_filename)?;
|
||||||
write!(state_file, "{}", new_state)?;
|
write!(state_file, "{}", new_state)?;
|
||||||
crate::git::add(&state_filename)?;
|
self.commit(&format!(
|
||||||
if crate::git::worktree_is_dirty(&self.dir.to_string_lossy())? {
|
|
||||||
crate::git::commit(
|
|
||||||
&self.dir,
|
|
||||||
&format!(
|
|
||||||
"change state of issue {}, {} -> {}",
|
"change state of issue {}, {} -> {}",
|
||||||
self.dir.file_name().unwrap().to_string_lossy(),
|
self.dir.file_name().unwrap().to_string_lossy(),
|
||||||
old_state,
|
old_state,
|
||||||
new_state,
|
new_state,
|
||||||
),
|
))?;
|
||||||
)?;
|
|
||||||
}
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -319,18 +306,12 @@ impl Issue {
|
||||||
assignee_filename.push("assignee");
|
assignee_filename.push("assignee");
|
||||||
let mut assignee_file = std::fs::File::create(&assignee_filename)?;
|
let mut assignee_file = std::fs::File::create(&assignee_filename)?;
|
||||||
write!(assignee_file, "{}", new_assignee)?;
|
write!(assignee_file, "{}", new_assignee)?;
|
||||||
crate::git::add(&assignee_filename)?;
|
self.commit(&format!(
|
||||||
if crate::git::worktree_is_dirty(&self.dir.to_string_lossy())? {
|
|
||||||
crate::git::commit(
|
|
||||||
&self.dir,
|
|
||||||
&format!(
|
|
||||||
"change assignee of issue {}, {} -> {}",
|
"change assignee of issue {}, {} -> {}",
|
||||||
self.dir.file_name().unwrap().to_string_lossy(),
|
self.dir.file_name().unwrap().to_string_lossy(),
|
||||||
old_assignee,
|
old_assignee,
|
||||||
new_assignee,
|
new_assignee,
|
||||||
),
|
))?;
|
||||||
)?;
|
|
||||||
}
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -444,7 +425,15 @@ impl Issue {
|
||||||
for tag in &self.tags {
|
for tag in &self.tags {
|
||||||
writeln!(tags_file, "{}", tag)?;
|
writeln!(tags_file, "{}", tag)?;
|
||||||
}
|
}
|
||||||
crate::git::add(&tags_filename)?;
|
self.commit(commit_message)?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn commit(&self, commit_message: &str) -> Result<(), IssueError> {
|
||||||
|
crate::git::add(&self.dir)?;
|
||||||
|
if !crate::git::worktree_is_dirty(&self.dir.to_string_lossy())? {
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
crate::git::commit(&self.dir, commit_message)?;
|
crate::git::commit(&self.dir, commit_message)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue