[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.
This commit is contained in:
Christophe Monniez 2018-12-05 14:23:08 +01:00
parent 248d23c2d0
commit 4f1a55da9b

View File

@ -722,19 +722,20 @@ 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
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),
@ -742,7 +743,7 @@ class runbot_build(models.Model):
"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)
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')):