mirror of
https://github.com/odoo/runbot.git
synced 2025-03-27 13:25:47 +07:00
[FIX] runbot_merge: updating PRs in repos without required statuses
The PR creation had been fixed to always validate even without a commit found (in case there was no need for a commit), but the update of a PR in such a situation was not tested, and thus naturally did not work because why would it work if it wasn't tested? Also remove the conditional skip on updating a PR to a new head.
This commit is contained in:
parent
8f09eacfb5
commit
c702fecda1
@ -1009,8 +1009,7 @@ class PullRequests(models.Model):
|
|||||||
newhead = vals.get('head')
|
newhead = vals.get('head')
|
||||||
if newhead:
|
if newhead:
|
||||||
c = self.env['runbot_merge.commit'].search([('sha', '=', newhead)])
|
c = self.env['runbot_merge.commit'].search([('sha', '=', newhead)])
|
||||||
if c.statuses:
|
self._validate(json.loads(c.statuses or '{}'))
|
||||||
self._validate(json.loads(c.statuses))
|
|
||||||
|
|
||||||
for pr in self:
|
for pr in self:
|
||||||
before, after = oldstate[pr], pr._tagstate
|
before, after = oldstate[pr], pr._tagstate
|
||||||
|
@ -937,29 +937,64 @@ def test_reopen_state(env, repo):
|
|||||||
assert pr.state == 'validated', \
|
assert pr.state == 'validated', \
|
||||||
"if a PR is reopened and had a CI'd head, it should be validated immediately"
|
"if a PR is reopened and had a CI'd head, it should be validated immediately"
|
||||||
|
|
||||||
def test_no_required_statuses(env, repo, config):
|
class TestNoRequiredStatus:
|
||||||
""" check that mergebot can work on a repo with no CI at all
|
def test_basic(self, env, repo, config):
|
||||||
"""
|
""" check that mergebot can work on a repo with no CI at all
|
||||||
env['runbot_merge.repository'].search([('name', '=', repo.name)]).required_statuses = False
|
"""
|
||||||
with repo:
|
env['runbot_merge.repository'].search([('name', '=', repo.name)]).required_statuses = False
|
||||||
m = repo.make_commit(None, 'initial', None, tree={'0': '0'})
|
with repo:
|
||||||
repo.make_ref('heads/master', m)
|
m = repo.make_commit(None, 'initial', None, tree={'0': '0'})
|
||||||
|
repo.make_ref('heads/master', m)
|
||||||
|
|
||||||
c = repo.make_commit(m, 'first', None, tree={'0': '1'})
|
c = repo.make_commit(m, 'first', None, tree={'0': '1'})
|
||||||
prx = repo.make_pr(title='title', body='body', target='master', head=c)
|
prx = repo.make_pr(title='title', body='body', target='master', head=c)
|
||||||
prx.post_comment('hansen r+', config['role_reviewer']['token'])
|
prx.post_comment('hansen r+', config['role_reviewer']['token'])
|
||||||
env.run_crons()
|
env.run_crons()
|
||||||
|
|
||||||
pr = env['runbot_merge.pull_requests'].search([
|
pr = env['runbot_merge.pull_requests'].search([
|
||||||
('repository.name', '=', repo.name),
|
('repository.name', '=', repo.name),
|
||||||
('number', '=', prx.number)
|
('number', '=', prx.number)
|
||||||
])
|
])
|
||||||
assert pr.state == 'ready'
|
assert pr.state == 'ready'
|
||||||
st = pr.staging_id
|
st = pr.staging_id
|
||||||
assert st
|
assert st
|
||||||
env.run_crons()
|
env.run_crons()
|
||||||
assert st.state == 'success'
|
assert st.state == 'success'
|
||||||
assert pr.state == 'merged'
|
assert pr.state == 'merged'
|
||||||
|
|
||||||
|
def test_updated(self, env, repo, config):
|
||||||
|
env['runbot_merge.repository'].search([('name', '=', repo.name)]).required_statuses = False
|
||||||
|
with repo:
|
||||||
|
m = repo.make_commit(None, 'initial', None, tree={'0': '0'})
|
||||||
|
repo.make_ref('heads/master', m)
|
||||||
|
|
||||||
|
c = repo.make_commit(m, 'first', None, tree={'0': '1'})
|
||||||
|
prx = repo.make_pr(title='title', body='body', target='master', head=c)
|
||||||
|
env.run_crons()
|
||||||
|
|
||||||
|
pr = env['runbot_merge.pull_requests'].search([
|
||||||
|
('repository.name', '=', repo.name),
|
||||||
|
('number', '=', prx.number)
|
||||||
|
])
|
||||||
|
assert pr.state == 'validated'
|
||||||
|
|
||||||
|
# normal push
|
||||||
|
with repo:
|
||||||
|
repo.make_commits(c, repo.Commit('second', tree={'0': '2'}), ref=prx.ref)
|
||||||
|
env.run_crons()
|
||||||
|
assert pr.state == 'validated'
|
||||||
|
with repo:
|
||||||
|
prx.post_comment('hansen r+', config['role_reviewer']['token'])
|
||||||
|
assert pr.state == 'ready'
|
||||||
|
|
||||||
|
# force push
|
||||||
|
with repo:
|
||||||
|
repo.make_commits(m, repo.Commit('xxx', tree={'0': 'm'}), ref=prx.ref)
|
||||||
|
env.run_crons()
|
||||||
|
assert pr.state == 'validated'
|
||||||
|
with repo:
|
||||||
|
prx.post_comment('hansen r+', config['role_reviewer']['token'])
|
||||||
|
assert pr.state == 'ready'
|
||||||
|
|
||||||
class TestRetry:
|
class TestRetry:
|
||||||
@pytest.mark.xfail(reason="This may not be a good idea as it could lead to tons of rebuild spam")
|
@pytest.mark.xfail(reason="This may not be a good idea as it could lead to tons of rebuild spam")
|
||||||
|
Loading…
Reference in New Issue
Block a user