issue.rs: add state getter/setter
This commit is contained in:
parent
343e43a762
commit
ed1b4488b2
1 changed files with 18 additions and 1 deletions
19
src/issue.rs
19
src/issue.rs
|
|
@ -4,7 +4,7 @@ use std::str::FromStr;
|
|||
#[cfg(feature = "log")]
|
||||
use log::debug;
|
||||
|
||||
#[derive(Debug, PartialEq, serde::Deserialize)]
|
||||
#[derive(Clone, Debug, PartialEq, serde::Deserialize)]
|
||||
/// These are the states an issue can be in.
|
||||
pub enum State {
|
||||
New,
|
||||
|
|
@ -157,6 +157,23 @@ impl Issue {
|
|||
None => self.description.as_str(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_state(&mut self, new_state: State) -> Result<(), IssueError> {
|
||||
let mut state_filename = std::path::PathBuf::from(&self.dir);
|
||||
state_filename.push("state");
|
||||
let mut state_file = std::fs::File::create(&state_filename)?;
|
||||
write!(state_file, "{}", new_state)?;
|
||||
crate::git::git_commit_file(&state_filename)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn read_state(&mut self) -> Result<(), IssueError> {
|
||||
let mut state_filename = std::path::PathBuf::from(&self.dir);
|
||||
state_filename.push("state");
|
||||
let state_string = std::fs::read_to_string(state_filename)?;
|
||||
self.state = State::from_str(state_string.trim())?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue