[snowpatch] [PATCH v2 4/5] Allow retrieving a check's description from Jenkins artifact

Russell Currey ruscur at russell.cc
Tue Dec 11 14:46:00 AEDT 2018


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 at russell.cc>
---
 src/jenkins.rs | 20 ++++++++++++++++++++
 src/main.rs    |  9 ++++++---
 2 files changed, 26 insertions(+), 3 deletions(-)

diff --git a/src/jenkins.rs b/src/jenkins.rs
index 4906139..1fbcc49 100644
--- a/src/jenkins.rs
+++ b/src/jenkins.rs
@@ -197,6 +197,26 @@ 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.status().is_success() {
+                    true => match resp.text() {
+                        Ok(text) => Some(text),
+                        Err(_e) => None,
+                    },
+                    false => 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)),
-- 
2.19.2



More information about the snowpatch mailing list