From 5d2fa12b69ae16d222f57bba7d427b5323a689e9 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Wed, 8 Nov 2017 22:47:28 +0100 Subject: 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. --- src/jenkins.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'src/jenkins.rs') 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 { .collect::>() } +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) -- cgit v1.2.3