[2/5] jenkins: Rename "build_url" to "build_handle"
diff mbox series

Message ID 20190201061714.7110-2-andrew.donnellan@au1.ibm.com
State Accepted
Headers show
Series
  • [1/5] Formatting cleanups
Related show

Commit Message

Andrew Donnellan Feb. 1, 2019, 6:17 a.m. UTC
In preparation for genericising our CI backend API, change references to
"build_url" to the more generic "build_handle", because the fact that it's
a URL is really a Jenkins-specific detail. Snowpatch cares about the fact
that a results URL is a URL, but not so much the build URL, which could be
any arbitrary identifier really.

Also some random formatting cleanups.

Signed-off-by: Andrew Donnellan <andrew.donnellan@au1.ibm.com>
---
 src/jenkins.rs | 42 ++++++++++++++++++++++--------------------
 src/main.rs    | 18 +++++++++---------
 2 files changed, 31 insertions(+), 29 deletions(-)

Patch
diff mbox series

diff --git a/src/jenkins.rs b/src/jenkins.rs
index 97dfe4f031db..547c396c3513 100644
--- a/src/jenkins.rs
+++ b/src/jenkins.rs
@@ -145,7 +145,7 @@  impl JenkinsBackend {
             .map_err(|e| format!("Couldn't parse JSON from Jenkins: {}", e).into())
     }
 
-    pub fn get_build_url(&self, build_queue_entry: &str) -> Result<String, Box<Error>> {
+    pub fn get_build_handle(&self, build_queue_entry: &str) -> Result<String, Box<Error>> {
         loop {
             let entry = self.get_api_json_object(build_queue_entry)?;
             match entry.get("executable") {
@@ -166,17 +166,17 @@  impl JenkinsBackend {
         }
     }
 
-    pub fn get_build_status(&self, build_url: &str) -> Result<JenkinsBuildStatus, Box<Error>> {
-        match self.get_api_json_object(build_url)?["building"].as_bool() {
+    pub fn get_build_status(&self, build_handle: &str) -> Result<JenkinsBuildStatus, Box<Error>> {
+        match self.get_api_json_object(build_handle)?["building"].as_bool() {
             Some(true) => Ok(JenkinsBuildStatus::Running),
             Some(false) => Ok(JenkinsBuildStatus::Done),
             None => Err("Error getting build status".into()),
         }
     }
 
-    pub fn get_build_result(&self, build_url: &str) -> Result<TestState, Box<Error>> {
+    pub fn get_build_result(&self, build_handle: &str) -> Result<TestState, Box<Error>> {
         match self
-            .get_api_json_object(build_url)?
+            .get_api_json_object(build_handle)?
             .get("result")
             .map(|v| v.as_str().unwrap_or("PENDING"))
         {
@@ -191,11 +191,11 @@  impl JenkinsBackend {
         }
     }
 
-    pub fn get_results_url(&self, build_url: &str, job: &BTreeMap<String, String>) -> String {
-        let default_url = format!("{}/", build_url);
+    pub fn get_results_url(&self, build_handle: &str, job: &BTreeMap<String, String>) -> String {
+        let default_url = format!("{}/", build_handle);
         match job.get("artifact") {
             Some(artifact) => {
-                let artifact_url = format!("{}/artifact/{}", build_url, artifact);
+                let artifact_url = format!("{}/artifact/{}", build_handle, artifact);
                 match self.get_url(&artifact_url) {
                     Ok(mut resp) => match resp.status().is_success() {
                         true => artifact_url,
@@ -210,27 +210,29 @@  impl JenkinsBackend {
 
     pub fn get_description(
         &self,
-        build_url: &str,
+        build_handle: &str,
         job: &BTreeMap<String, String>,
     ) -> Option<String> {
         match job.get("description") {
-            Some(artifact) => match self.get_url(&format!("{}/artifact/{}", build_url, artifact)) {
-                Ok(mut resp) => match resp.status().is_success() {
-                    true => match resp.text() {
-                        Ok(text) => Some(text),
-                        Err(_e) => None,
+            Some(artifact) => {
+                match self.get_url(&format!("{}/artifact/{}", build_handle, artifact)) {
+                    Ok(mut resp) => match resp.status().is_success() {
+                        true => match resp.text() {
+                            Ok(text) => Some(text),
+                            Err(_e) => None,
+                        },
+                        false => None,
                     },
-                    false => None,
-                },
-                Err(_e) => None,
-            },
+                    Err(_e) => None,
+                }
+            }
             None => None,
         }
     }
 
-    pub fn wait_build(&self, build_url: &str) -> Result<JenkinsBuildStatus, Box<Error>> {
+    pub fn wait_build(&self, build_handle: &str) -> Result<JenkinsBuildStatus, Box<Error>> {
         // TODO: Implement a timeout?
-        while self.get_build_status(build_url)? != JenkinsBuildStatus::Done {
+        while self.get_build_status(build_handle)? != JenkinsBuildStatus::Done {
             sleep(Duration::from_millis(JENKINS_POLLING_INTERVAL));
         }
         Ok(JenkinsBuildStatus::Done)
diff --git a/src/main.rs b/src/main.rs
index 2ca2b007ecba..19989c87cb01 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -134,23 +134,23 @@  fn run_tests(
             .start_test(&job.job, jenkins_params)
             .unwrap_or_else(|err| panic!("Starting Jenkins test failed: {}", err));
         debug!("{:?}", &res);
-        let build_url_real;
+        let build_handle_real;
         loop {
-            let build_url = jenkins.get_build_url(&res);
-            if let Ok(url) = build_url {
-                build_url_real = url;
+            let build_handle = jenkins.get_build_handle(&res);
+            if let Ok(handle) = build_handle {
+                build_handle_real = handle;
                 break;
             } // TODO: Handle error
         }
-        debug!("Build URL: {}", build_url_real);
-        jenkins.wait_build(&build_url_real).unwrap(); // TODO: Error correctly
-        let mut test_result = jenkins.get_build_result(&build_url_real).unwrap();
+        debug!("Build URL: {}", build_handle_real);
+        jenkins.wait_build(&build_handle_real).unwrap(); // TODO: Error correctly
+        let mut test_result = jenkins.get_build_result(&build_handle_real).unwrap();
         info!("Jenkins job for {}/{} complete.", branch_name, job.title);
         if test_result == TestState::Fail && job.warn_on_fail {
             test_result = TestState::Warning;
         }
         results.push(TestResult {
-            description: match jenkins.get_description(&build_url_real, &job.parameters) {
+            description: match jenkins.get_description(&build_handle_real, &job.parameters) {
                 Some(description) => Some(description),
                 None => Some(
                     format!("Test {} on branch {}", job.title, branch_name.to_string()).to_string(),
@@ -158,7 +158,7 @@  fn run_tests(
             },
             state: test_result,
             context: Some(job.title.replace("/", "_")),
-            target_url: Some(jenkins.get_results_url(&build_url_real, &job.parameters)),
+            target_url: Some(jenkins.get_results_url(&build_handle_real, &job.parameters)),
         });
     }
     results