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

Andrew Donnellan andrew.donnellan at au1.ibm.com
Tue Dec 11 19:20:29 AEDT 2018



On 11/12/18 2:46 pm, Russell Currey wrote:
> 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") {

can't decide how much I love my beautiful custom deserialiser for Job types

> +            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,

I think "match resp.status().is_success()" isn't very rustic, any neater 
way to pattern match the response type?

> +                },
> +                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)),
> 

-- 
Andrew Donnellan              OzLabs, ADL Canberra
andrew.donnellan at au1.ibm.com  IBM Australia Limited



More information about the snowpatch mailing list