diff options
| author | Teddy Wing | 2017-11-08 21:07:26 +0100 | 
|---|---|---|
| committer | Teddy Wing | 2017-11-08 21:07:26 +0100 | 
| commit | 7fc89d6d3b9fb12adcfe11609683d53d37b959fd (patch) | |
| tree | 693e3154efb9d7fb32441e4f8ea8d07585344a51 /src | |
| parent | e0dca75f9b2de9023ecb978a0f9c8a11b905bcd1 (diff) | |
| download | kipper-7fc89d6d3b9fb12adcfe11609683d53d37b959fd.tar.bz2 | |
github.rs: Fix compilation errors from e0dca75f9b2de9023ecb978a0f9c8a11b
* Import 'reqwest'
* Import `HashMap`
* Insert `state` as string instead of `CommitStatus` (implement
  `fmt::Display` in order to do this)
* Insert `description` as string instead of `Option`
* Make test string arguments owned strings
Diffstat (limited to 'src')
| -rw-r--r-- | src/github.rs | 26 | 
1 files changed, 22 insertions, 4 deletions
| diff --git a/src/github.rs b/src/github.rs index b297886..18fdd3c 100644 --- a/src/github.rs +++ b/src/github.rs @@ -1,4 +1,8 @@  extern crate mockito; +extern crate reqwest; + +use std::collections::HashMap; +use std::fmt;  use pull_request::CommitRef; @@ -15,6 +19,17 @@ enum CommitStatus {      Success,  } +impl fmt::Display for CommitStatus { +    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { +        match *self { +            CommitStatus::Error => write!(f, "error"), +            CommitStatus::Failure => write!(f, "failure"), +            CommitStatus::Pending => write!(f, "pending"), +            CommitStatus::Success => write!(f, "success"), +        } +    } +} +  fn update_commit_status(      commit_ref: CommitRef,      state: CommitStatus, @@ -25,11 +40,14 @@ fn update_commit_status(      let client = reqwest::Client::new();      let mut params = HashMap::new(); -    params.insert("state", state); +    params.insert("state", state.to_string());      params.insert("target_url", target_url); -    params.insert("description", description);      params.insert("context", context); +    if let Some(d) = description { +        params.insert("description", d); +    } +      let response = client.post(          format!("{}/repos/{}/{}/statuses/{}", API_URL, commit_ref.repo, commit_ref.sha)      ); @@ -57,9 +75,9 @@ mod tests {          update_commit_status(              commit_ref,              CommitStatus::Success, -            "https://jenkins.example.com/job/octocat/3", +            "https://jenkins.example.com/job/octocat/3".to_string(),              None, -            "continuous-integration/jenkins" +            "continuous-integration/jenkins".to_string()          );          mock.assert(); | 
