[snowpatch] [PATCH v2 4/5] Allow retrieving a check's description from Jenkins artifact
Russell Currey
ruscur at russell.cc
Thu Dec 13 14:28:33 AEDT 2018
On Tue, 2018-12-11 at 19:20 +1100, Andrew Donnellan wrote:
>
> 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?
is_success() covers anything in the 200-299 range though, whereas (for
example) matching on StatusCode::OK only gets exactly 200, which
*would* probably be fine, but this is Jenkins we're talking about.
>
> > + },
> > + 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)),
> >
More information about the snowpatch
mailing list