commitstatus: Trim description to 140 characters if it is too long

This commit is contained in:
Graham Christensen 2020-03-31 17:11:14 -04:00
parent 9f70ab9c13
commit 5730914971
No known key found for this signature in database
GPG key ID: FE918C3A98C1030F

View file

@ -46,12 +46,19 @@ impl<'a> CommitStatus<'a> {
} }
pub fn set(&self, state: hubcaps::statuses::State) { pub fn set(&self, state: hubcaps::statuses::State) {
let desc = if self.description.len() >= 140 {
eprintln!("Warning: description is over 140 char; truncating: {:?}", &self.description);
self.description.chars().take(140).collect()
} else {
self.description.clone()
};
self.api self.api
.create( .create(
self.sha.as_ref(), self.sha.as_ref(),
&hubcaps::statuses::StatusOptions::builder(state) &hubcaps::statuses::StatusOptions::builder(state)
.context(self.context.clone()) .context(self.context.clone())
.description(self.description.clone()) .description(desc)
.target_url(self.url.clone()) .target_url(self.url.clone())
.build(), .build(),
) )