From 32ef9027fd4690a0ad99987ee53f9de1788d07ab Mon Sep 17 00:00:00 2001 From: Louis Vallat Date: Fri, 3 Jun 2022 22:49:07 +0200 Subject: [PATCH] Added a check on pipeline retry/creation in case the user doesn't have sufficient rights Signed-off-by: Louis Vallat --- src/gitlab_controller.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/gitlab_controller.rs b/src/gitlab_controller.rs index 463ab32..79fb188 100644 --- a/src/gitlab_controller.rs +++ b/src/gitlab_controller.rs @@ -121,7 +121,7 @@ pub fn retry_pipeline(host: &str, token: &str, project: &Project) { warn!("{:?} has no pipeline, ignoring.", project); return; } - let res: Pipeline; + let res: Option; if pipeline.clone().unwrap().status == "success" { debug!("Latest pipeline for {:?} has a 'success' status, creating another one.", project); @@ -129,7 +129,7 @@ pub fn retry_pipeline(host: &str, token: &str, project: &Project) { .project(project.name.clone()) .ref_(project.ref_.clone()) .build().unwrap(); - res = endpoint.query(&client).unwrap(); + res = endpoint.query(&client).ok(); } else { debug!("Latest pipeline status for {:?} wasn't a success, retrying.", project); @@ -137,8 +137,12 @@ pub fn retry_pipeline(host: &str, token: &str, project: &Project) { .project(project.name.clone()) .pipeline(pipeline.unwrap().id) .build().unwrap(); - res = endpoint.query(&client).unwrap(); + res = endpoint.query(&client).ok(); + } + if res.is_none() { + error!("Could not retry/create a new pipeline for project {:?}. Ignoring.", project); + } else { + debug!("API answer was {:?}.", res.unwrap()); } - debug!("API answer was {:?}.", res); }