mirror of
https://github.com/odoo/runbot.git
synced 2025-03-15 23:45:44 +07:00
[FIX] runbot_merge: validate PRs on head update
If a PR gets sync'd to a known-valid commit, it should be marked as valid rather than get in this weird state where it's merely open but github knows it passes CI. Fixes #72
This commit is contained in:
parent
1d2c264728
commit
b699ea7f47
@ -720,7 +720,15 @@ class PullRequests(models.Model):
|
||||
@api.multi
|
||||
def write(self, vals):
|
||||
oldstate = { pr: pr._tagstate for pr in self }
|
||||
|
||||
w = super().write(vals)
|
||||
|
||||
newhead = vals.get('head')
|
||||
if newhead:
|
||||
c = self.env['runbot_merge.commit'].search([('sha', '=', newhead)])
|
||||
if c.statuses:
|
||||
self._validate(json.loads(c.statuses))
|
||||
|
||||
for pr in self:
|
||||
before, after = oldstate[pr], pr._tagstate
|
||||
if after != before:
|
||||
|
@ -1614,6 +1614,30 @@ class TestPRUpdate(object):
|
||||
|
||||
assert not env['runbot_merge.pull_requests'].search([('number', '=', prx.number)])
|
||||
|
||||
def test_update_to_ci(self, env, repo):
|
||||
""" If a PR is updated to a known-valid commit, it should be
|
||||
validated
|
||||
"""
|
||||
m = repo.make_commit(None, 'initial', None, tree={'m': 'm'})
|
||||
repo.make_ref('heads/master', m)
|
||||
|
||||
c = repo.make_commit(m, 'fist', None, tree={'m': 'c1'})
|
||||
c2 = repo.make_commit(m, 'first', None, tree={'m': 'cc'})
|
||||
repo.post_status(c2, 'success', 'legal/cla')
|
||||
repo.post_status(c2, 'success', 'ci/runbot')
|
||||
|
||||
prx = repo.make_pr('title', 'body', target='master', ctid=c, user='user')
|
||||
pr = env['runbot_merge.pull_requests'].search([
|
||||
('repository.name', '=', repo.name),
|
||||
('number', '=', prx.number),
|
||||
])
|
||||
assert pr.head == c
|
||||
assert pr.state == 'opened'
|
||||
|
||||
prx.push(c2)
|
||||
assert pr.head == c2
|
||||
assert pr.state == 'validated'
|
||||
|
||||
class TestBatching(object):
|
||||
def _pr(self, repo, prefix, trees, *,
|
||||
target='master', user='user', reviewer='reviewer',
|
||||
|
Loading…
Reference in New Issue
Block a user