[v2,5/5] jenkins: Only link to artifact if it actually exists
diff mbox series

Message ID 20181211034601.29061-5-ruscur@russell.cc
State Accepted
Headers show
Series
  • [v2,1/5] setup_rustfmt_hook: create hooks dir if it doesn't exist
Related show

Commit Message

Russell Currey Dec. 11, 2018, 3:46 a.m. UTC
Signed-off-by: Russell Currey <ruscur@russell.cc>
---
 src/jenkins.rs | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

Comments

Andrew Donnellan Dec. 11, 2018, 8:21 a.m. UTC | #1
On 11/12/18 2:46 pm, Russell Currey wrote:
> Signed-off-by: Russell Currey <ruscur@russell.cc>
> ---
>   src/jenkins.rs | 14 ++++++++++++--
>   1 file changed, 12 insertions(+), 2 deletions(-)
> 
> diff --git a/src/jenkins.rs b/src/jenkins.rs
> index 1fbcc49..67d729e 100644
> --- a/src/jenkins.rs
> +++ b/src/jenkins.rs
> @@ -191,9 +191,19 @@ impl JenkinsBackend {
>       }
>   
>       pub fn get_results_url(&self, build_url: &str, job: &BTreeMap<String, String>) -> String {
> +        let default_url = format!("{}/", build_url);
>           match job.get("artifact") {
> -            Some(artifact) => format!("{}/artifact/{}", build_url, artifact),
> -            None => format!("{}/", build_url),
> +            Some(artifact) => {
> +                let artifact_url = format!("{}/artifact/{}", build_url, artifact);
> +                match self.get_url(&artifact_url) {
> +                    Ok(mut resp) => match resp.status().is_success() {
> +                        true => artifact_url,
> +                        false => default_url,

same comment as last patch

> +                    },
> +                    Err(_e) => default_url,
> +                }
> +            }
> +            None => default_url,
>           }
>       }
>   
>

Patch
diff mbox series

diff --git a/src/jenkins.rs b/src/jenkins.rs
index 1fbcc49..67d729e 100644
--- a/src/jenkins.rs
+++ b/src/jenkins.rs
@@ -191,9 +191,19 @@  impl JenkinsBackend {
     }
 
     pub fn get_results_url(&self, build_url: &str, job: &BTreeMap<String, String>) -> String {
+        let default_url = format!("{}/", build_url);
         match job.get("artifact") {
-            Some(artifact) => format!("{}/artifact/{}", build_url, artifact),
-            None => format!("{}/", build_url),
+            Some(artifact) => {
+                let artifact_url = format!("{}/artifact/{}", build_url, artifact);
+                match self.get_url(&artifact_url) {
+                    Ok(mut resp) => match resp.status().is_success() {
+                        true => artifact_url,
+                        false => default_url,
+                    },
+                    Err(_e) => default_url,
+                }
+            }
+            None => default_url,
         }
     }