[3/3] Allow retrieving a check's description from Jenkins artifact
diff mbox series

Message ID 20181109042154.16361-3-ruscur@russell.cc
State Superseded
Headers show
Series
  • [1/3] setup_rustfmt_hook: create hooks dir if it doesn't exist
Related show

Commit Message

Russell Currey Nov. 9, 2018, 4:21 a.m. UTC
By specifying the "description" parameter in a job, take the contents
of a Jenkins artifact and use it to populate the description field.

Closes #49

Signed-off-by: Russell Currey <ruscur@russell.cc>
---
 src/jenkins.rs | 17 +++++++++++++++++
 src/main.rs    |  9 ++++++---
 2 files changed, 23 insertions(+), 3 deletions(-)

Patch
diff mbox series

diff --git a/src/jenkins.rs b/src/jenkins.rs
index 4906139..2706fc8 100644
--- a/src/jenkins.rs
+++ b/src/jenkins.rs
@@ -197,6 +197,23 @@  impl JenkinsBackend {
         }
     }
 
+    pub fn get_description(
+        &self,
+        build_url: &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.text() {
+                    Ok(text) => Some(text),
+                    Err(_e) => None,
+                },
+                Err(_e) => None,
+            },
+            None => None,
+        }
+    }
+
     pub fn wait_build(&self, build_url: &str) -> JenkinsBuildStatus {
         // TODO: Implement a timeout?
         while self.get_build_status(build_url) != JenkinsBuildStatus::Done {
diff --git a/src/main.rs b/src/main.rs
index 6fe0bdb..c002b8b 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -148,9 +148,12 @@  fn run_tests(
             test_result = TestState::Warning;
         }
         results.push(TestResult {
-            description: Some(
-                format!("Test {} on branch {}", job.title, branch_name.to_string()).to_string(),
-            ),
+            description: match jenkins.get_description(&build_url_real, &job.parameters) {
+                Some(description) => Some(description),
+                None => Some(
+                    format!("Test {} on branch {}", job.title, branch_name.to_string()).to_string(),
+                ),
+            },
             state: test_result,
             context: Some(job.title.replace("/", "_")),
             target_url: Some(jenkins.get_results_url(&build_url_real, &job.parameters)),