diff options
| author | Teddy Wing | 2017-11-09 00:50:59 +0100 | 
|---|---|---|
| committer | Teddy Wing | 2017-11-09 00:55:52 +0100 | 
| commit | 26b74edece4546378c8a853cc70f7388f20ff0c6 (patch) | |
| tree | 6faa7819a7a680ff62e9fb3432211170a488cdaf | |
| parent | 2d3b362513d7e256f6a1ed3bdeed2eb785302ff3 (diff) | |
| download | kipper-26b74edece4546378c8a853cc70f7388f20ff0c6.tar.bz2 | |
github.rs: `update_commit_status` should take a repo name
Pass a repo name explicitly in an argument to the function. We now have
the values we need to be able to properly construct a URL to POST to.
Update our HTTP request to send the params as JSON and include the
"Accept" header that GitHub recommends adding
(https://developer.github.com/v3/#current-version) based on the code
examples in
https://docs.rs/reqwest/0.8.1/reqwest/header/struct.Accept.html#examples.
| -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 18fdd3c..f8bf97d 100644 --- a/src/github.rs +++ b/src/github.rs @@ -4,6 +4,8 @@ extern crate reqwest;  use std::collections::HashMap;  use std::fmt; +use self::reqwest::header::{Accept, qitem}; +  use pull_request::CommitRef;  #[cfg(not(test))] @@ -12,7 +14,7 @@ const API_URL: &'static str = "https://api.github.com";  #[cfg(test)]  const API_URL: &'static str = mockito::SERVER_URL; -enum CommitStatus { +pub enum CommitStatus {      Error,      Failure,      Pending, @@ -30,7 +32,8 @@ impl fmt::Display for CommitStatus {      }  } -fn update_commit_status( +pub fn update_commit_status( +    repo_name: String,      commit_ref: CommitRef,      state: CommitStatus,      target_url: String, @@ -49,8 +52,22 @@ fn update_commit_status(      }      let response = client.post( -        format!("{}/repos/{}/{}/statuses/{}", API_URL, commit_ref.repo, commit_ref.sha) -    ); +            &format!( +                "{}/repos/{}/{}/statuses/{}", +                API_URL, +                repo_name, +                commit_ref.repo, +                commit_ref.sha +            ) +        ) +        .header( +            Accept( +                vec![qitem("application/vnd.github.v3+json".parse().unwrap())] +            ) +        ) +        .json(¶ms) +        .send() +        .unwrap();  } @@ -73,6 +90,7 @@ mod tests {          };          update_commit_status( +            "octocat".to_string(),              commit_ref,              CommitStatus::Success,              "https://jenkins.example.com/job/octocat/3".to_string(), | 
