diff options
author | Teddy Wing | 2017-11-12 18:52:21 +0100 |
---|---|---|
committer | Teddy Wing | 2017-11-12 18:52:21 +0100 |
commit | 1b2f71944f50ae3032737c0566c20ad046789b37 (patch) | |
tree | 6bfcddc79e56a5b906d2be9134588b451a5e7ba3 /src/jenkins.rs | |
parent | 9db1426ede96774db40cbf0cdf42021fa9bc80c4 (diff) | |
download | kipper-1b2f71944f50ae3032737c0566c20ad046789b37.tar.bz2 |
Take Jenkins URL from command line options
Get rid of the static, global `API_URL`, and replace it with the Jenkins
URL that gets passed into `find_and_track_build_and_update_status()`.
This necessitated adding a new URL argument to `get_jobs()` and
`request_job()`. Starting to wonder if I should be creating a struct to
hold the URL and client that I can attach these functions to as methods,
but for now I'll leave them alone.
Diffstat (limited to 'src/jenkins.rs')
-rw-r--r-- | src/jenkins.rs | 48 |
1 files changed, 34 insertions, 14 deletions
diff --git a/src/jenkins.rs b/src/jenkins.rs index 7402909..fd72e73 100644 --- a/src/jenkins.rs +++ b/src/jenkins.rs @@ -37,12 +37,6 @@ use af83; use github; use pull_request::CommitRef; -#[cfg(not(test))] -const API_URL: &'static str = "http://jenkins.example.com"; - -#[cfg(test)] -const API_URL: &'static str = mockito::SERVER_URL; - #[derive(Debug, PartialEq, Eq)] pub enum JobStatus { Success, @@ -91,11 +85,26 @@ pub fn find_and_track_build_and_update_status( &jenkins_user_id, &jenkins_token )?; - let jobs = get_jobs(&jenkins_client, commit_ref.repo.as_ref())?; + + #[cfg(not(test))] + let jenkins_url = jenkins_url.to_owned(); + + #[cfg(test)] + let jenkins_url = mockito::SERVER_URL; + + let jobs = get_jobs( + &jenkins_url, + &jenkins_client, + commit_ref.repo.as_ref() + )?; let t20_minutes = 60 * 20; for job_url in jobs { - let mut job = request_job(&jenkins_client, job_url.as_ref())?; + let mut job = request_job( + &jenkins_url, + &jenkins_client, + job_url.as_ref() + )?; // Does `displayName` match if job_for_commit(&job, &commit_ref) { @@ -153,6 +162,7 @@ pub fn find_and_track_build_and_update_status( sleep(Duration::from_secs(30)); let updated_job = request_job( + &jenkins_url, &jenkins_client, job_url.as_ref() ).expect( @@ -196,9 +206,14 @@ pub fn auth_credentials(user_id: String, token: String) -> header::Basic { } } -pub fn get_jobs(client: &reqwest::Client, repo_name: &str) -> Result<Vec<String>, Box<Error>> { - let mut response = client.get(&format!("{}/job/{}-branches/api/json", API_URL, repo_name)) - .send()?; +pub fn get_jobs( + jenkins_url: &String, + client: &reqwest::Client, + repo_name: &str +) -> Result<Vec<String>, Box<Error>> { + let mut response = client.get( + &format!("{}/job/{}-branches/api/json", jenkins_url, repo_name) + ).send()?; let body = response.text()?; @@ -213,11 +228,16 @@ pub fn get_jobs(client: &reqwest::Client, repo_name: &str) -> Result<Vec<String> ) } -pub fn request_job(client: &reqwest::Client, url: &str) -> Result<Job, Box<Error>> { +pub fn request_job( + jenkins_url: &String, + client: &reqwest::Client, + url: &str +) -> Result<Job, Box<Error>> { let url = Url::parse(url.as_ref())?; - let mut response = client.get(&format!("{}{}/api/json", API_URL, url.path())) - .send()?; + let mut response = client.get( + &format!("{}{}/api/json", jenkins_url, url.path()) + ).send()?; let body = response.text()?; |