From 4f1a55da9beb1099a03c02034a8900d63571f4b2 Mon Sep 17 00:00:00 2001 From: Christophe Monniez Date: Wed, 5 Dec 2018 14:23:08 +0100 Subject: [PATCH] [FIX] runbot: reduce the amount of github status When commit is built serveral times, each time the status is updated, a request is sent to github for each build. As a side effect, if the first build is a failure and the last one a success, github is wrongly updated to failure. This bug is particulary annoying on PR in conjunction with the runbot_merge, preventing a the PR to be merged even after several rebuild. With this commit, only the latest build per repository is used to update the github status. The amount of github status updates is also reduced. --- runbot/models/build.py | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/runbot/models/build.py b/runbot/models/build.py index 5d1461ea..663fefae 100644 --- a/runbot/models/build.py +++ b/runbot/models/build.py @@ -722,27 +722,28 @@ class runbot_build(models.Model): """Notify github of failed/successful builds""" runbot_domain = self.env['runbot.repo']._domain() for build in self: - b = build.duplicate_id if build.state == 'duplicate' else build desc = "runbot build %s" % (build.dest,) - if b.state == 'testing': + if build.state == 'testing': state = 'pending' - elif b.state in ('running', 'done'): + elif build.state in ('running', 'done'): state = 'error' - if b.result == 'ok': + if build.result == 'ok': state = 'success' - if b.result == 'ko': + if build.result == 'ko': state = 'failure' - desc += " (runtime %ss)" % (b.job_time,) + desc += " (runtime %ss)" % (build.job_time,) else: continue - status = { - "state": state, - "target_url": "http://%s/runbot/build/%s" % (runbot_domain, build.id), - "description": desc, - "context": "ci/runbot" - } - _logger.debug("github updating status %s to %s", build.name, state) - build.repo_id._github('/repos/:owner/:repo/statuses/%s' % build.name, status, ignore_errors=True) + commits = {(b.repo_id, b.name) for b in self.search([('name', '=', build.name)])} + for repo, commit_hash in commits: + status = { + "state": state, + "target_url": "http://%s/runbot/build/%s" % (runbot_domain, build.id), + "description": desc, + "context": "ci/runbot" + } + _logger.debug("github updating status %s to %s", build.name, state) + repo._github('/repos/:owner/:repo/statuses/%s' % commit_hash, status, ignore_errors=True) # Jobs definitions # They all need "build, lock_pathn log_path" parameters @@ -837,9 +838,7 @@ class runbot_build(models.Model): else: v['result'] = "ko" build.write(v) - # post statuses on duplicate too - for b in self.search([('name', '=', build.name)]): - b._github_status() + build._github_status() # run server cmd, mods = build._cmd() if os.path.exists(build._server('addons/im_livechat')):