From 52454dc018218286e4ef8e79b85feb8f426dfd31 Mon Sep 17 00:00:00 2001 From: James Westman Date: Mon, 22 May 2023 16:33:37 -0500 Subject: [PATCH] Fix bugs in check jobs - When a check job marked itself as failed using the API, update_build_status_after_check would notice that the build is no longer in the Validating state and think something was wrong. Fixed by making it do nothing if the build is already marked as failed. - Change the JSON job results from null to {} --- src/jobs/check_job.rs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/jobs/check_job.rs b/src/jobs/check_job.rs index 6bec3dd..dcee9b6 100644 --- a/src/jobs/check_job.rs +++ b/src/jobs/check_job.rs @@ -137,7 +137,7 @@ impl JobInstance for CheckJobInstance { Ok(()) })?; - Ok(json! {()}) + Ok(json!({})) } } @@ -175,13 +175,18 @@ pub fn update_build_status_after_check( .for_update() .get_result::(conn)?; + let repo_state = RepoState::from_db(build.repo_state, &build.repo_state_reason); + + if matches!(repo_state, RepoState::Failed(_)) { + /* If the build has already failed, don't change its status */ + return Ok(()); + } + // Sanity check--make sure the build is still in Validating state - if !RepoState::from_db(build.repo_state, &build.repo_state_reason) - .same_state_as(&RepoState::Validating) - { + if !matches!(repo_state, RepoState::Validating) { return Err(JobError::new(&format!( "Expected repo to be in {:?} state upon check completion, but it was in {:?}", - RepoState::Committing, + RepoState::Validating, RepoState::from_db(build.repo_state, &build.repo_state_reason) ))); }