aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTeddy Wing2017-11-08 22:47:28 +0100
committerTeddy Wing2017-11-08 22:47:28 +0100
commit5d2fa12b69ae16d222f57bba7d427b5323a689e9 (patch)
tree2e12333ad13c54fa32f63994cdb6a4516966261c /src
parentd93d73e1a3504a84cd4a017174a8665a739e8045 (diff)
downloadkipper-5d2fa12b69ae16d222f57bba7d427b5323a689e9.tar.bz2
jenkins.rs: Initial `request_job` implementation
Try to request a job from the Jenkins API and return it as a `Job`. Trouble is, we can't mock this because the 'mockito' mocker depends on `API_URL`. Right now, we're making a request to the real server, not the mock server.
Diffstat (limited to 'src')
-rw-r--r--src/jenkins.rs20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/jenkins.rs b/src/jenkins.rs
index 1879574..ff15428 100644
--- a/src/jenkins.rs
+++ b/src/jenkins.rs
@@ -101,6 +101,26 @@ pub fn get_jobs(repo_name: String) -> Vec<String> {
.collect::<Vec<String>>()
}
+pub fn request_job(url: String) -> Job {
+ let client = reqwest::Client::new();
+
+ let credentials = auth_credentials();
+
+ let mut response = client.get(&format!("{}/api/json", url))
+ .header(Authorization(credentials))
+ .send()
+ .unwrap();
+
+ let body = response.text().unwrap();
+
+ let mut job = json::parse(body.as_ref()).unwrap();
+
+ Job {
+ display_name: job["displayName"].take_string().unwrap(),
+ result: result_from_job(job["result"].take_string()),
+ }
+}
+
// Does the `commit_ref` correspond to the job?
pub fn job_for_commit(job: Job, commit_ref: CommitRef) -> bool {
job.display_name == af83::job_name(commit_ref)