[IMP] runbot_merge: attempt to fix race condition

Because mergebot cron can run on any runbot, it's apparently possible
that a staging gets merged and the "closed" feedback from github
overwrites the merged status which the mergebot is supposed to set
despite the supposed protection.
This commit is contained in:
Xavier Morel 2018-10-08 16:27:40 +02:00
parent e590d565c1
commit dd29e6b8a8

View File

@ -166,12 +166,18 @@ def handle_pr(env, event):
# don't marked merged PRs as closed (!!!) # don't marked merged PRs as closed (!!!)
if event['action'] == 'closed' and pr_obj.state != 'merged': if event['action'] == 'closed' and pr_obj.state != 'merged':
pr_obj.state = 'closed' env.cr.execute('''
pr_obj.staging_id.cancel( UPDATE runbot_merge_pull_requests
"PR %s:%s closed by %s", SET state = 'closed'
pr_obj.repository.name, pr_obj.number, WHERE id = %s AND state != 'merged'
event['sender']['login'] ''', [pr_obj.id])
) env.cr.commit()
if env.cr.rowcount:
pr_obj.staging_id.cancel(
"PR %s:%s closed by %s",
pr_obj.repository.name, pr_obj.number,
event['sender']['login']
)
return 'Closed {}'.format(pr_obj.id) return 'Closed {}'.format(pr_obj.id)
if event['action'] == 'reopened' and pr_obj.state == 'closed': if event['action'] == 'reopened' and pr_obj.state == 'closed':