From bef6a8e2d0e7df4bf0a5b137ae84b2d6e30bfdaf Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Wed, 11 Aug 2021 15:10:22 +0200 Subject: [PATCH] [FIX] runbot_merge: point to the right status on staging failure On staging failure, the 'bot would point to the first error or failure status it found on the commit. This turns out not to be correct as we (now) have various statuses which are optional, and may fail without blocking stagings (either because they're solely informational or because they're blocking & overridable on PRs). Fix this so the 'bot points to the first *required* failure. Fixes #517 --- runbot_merge/models/pull_requests.py | 12 +++++++++--- runbot_merge/tests/test_basic.py | 1 + 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/runbot_merge/models/pull_requests.py b/runbot_merge/models/pull_requests.py index 431def74..a5e2a0e5 100644 --- a/runbot_merge/models/pull_requests.py +++ b/runbot_merge/models/pull_requests.py @@ -1847,12 +1847,18 @@ class Stagings(models.Model): if repo.endswith('^'): continue - commit = self.env['runbot_merge.commit'].search([ - ('sha', '=', head) - ]) + required_statuses = set( + self.env['runbot_merge.repository'] + .search([('name', '=', repo)]) + .status_ids + ._for_staging(self) + .mapped('context')) + + commit = self.env['runbot_merge.commit'].search([('sha', '=', head)]) statuses = json.loads(commit.statuses or '{}') reason = next(( ctx for ctx, result in statuses.items() + if ctx in required_statuses if to_status(result).get('state') in ('error', 'failure') ), None) if not reason: diff --git a/runbot_merge/tests/test_basic.py b/runbot_merge/tests/test_basic.py index 08730262..69cb0879 100644 --- a/runbot_merge/tests/test_basic.py +++ b/runbot_merge/tests/test_basic.py @@ -560,6 +560,7 @@ def test_staging_ci_failure_single(env, repo, users, config): staging_head = repo.commit('heads/staging.master') with repo: + repo.post_status(staging_head.id, 'failure', 'a/b') repo.post_status(staging_head.id, 'success', 'legal/cla') repo.post_status(staging_head.id, 'failure', 'ci/runbot') # stable genius env.run_crons()