forked from the-distro/ofborg
commitstatus: return an error if we fail to set a status
This commit is contained in:
parent
3e5132596b
commit
0ae112f976
|
@ -36,18 +36,25 @@ impl<'a> CommitStatus<'a> {
|
|||
self.url = url.unwrap_or_else(|| String::from(""))
|
||||
}
|
||||
|
||||
pub fn set_with_description(&mut self, description: &str, state: hubcaps::statuses::State) {
|
||||
pub fn set_with_description(
|
||||
&mut self,
|
||||
description: &str,
|
||||
state: hubcaps::statuses::State,
|
||||
) -> Result<(), CommitStatusError> {
|
||||
self.set_description(description.to_owned());
|
||||
self.set(state);
|
||||
self.set(state)
|
||||
}
|
||||
|
||||
pub fn set_description(&mut self, description: String) {
|
||||
self.description = description;
|
||||
}
|
||||
|
||||
pub fn set(&self, state: hubcaps::statuses::State) {
|
||||
pub fn set(&self, state: hubcaps::statuses::State) -> Result<(), CommitStatusError> {
|
||||
let desc = if self.description.len() >= 140 {
|
||||
eprintln!("Warning: description is over 140 char; truncating: {:?}", &self.description);
|
||||
eprintln!(
|
||||
"Warning: description is over 140 char; truncating: {:?}",
|
||||
&self.description
|
||||
);
|
||||
self.description.chars().take(140).collect()
|
||||
} else {
|
||||
self.description.clone()
|
||||
|
@ -62,6 +69,11 @@ impl<'a> CommitStatus<'a> {
|
|||
.target_url(self.url.clone())
|
||||
.build(),
|
||||
)
|
||||
.expect("Failed to mark final status on commit");
|
||||
.map(|_| ())
|
||||
.map_err(|e| CommitStatusError::HubcapsError(e))
|
||||
}
|
||||
}
|
||||
|
||||
pub enum CommitStatusError {
|
||||
HubcapsError(hubcaps::Error),
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue