[FIX] fwbot: properly prevent @up to on forward-port PRs

There was already a check, but the way the check behaved
means *detached* PRs would not be prevented from setting their
forward-port, despite that not doing anything.

Fix it by checking if the current PR has a source, not a parent.

Fixes #465
This commit is contained in:
Xavier Morel 2021-07-26 14:00:14 +02:00 committed by xmo-odoo
parent 6a8c13b1ef
commit f10d33ee85
2 changed files with 31 additions and 7 deletions

View File

@ -350,11 +350,10 @@ class PullRequests(models.Model):
('project_id', '=', self.repository.project_id.id),
('name', '=', limit),
])
if self.parent_id:
msg = "Sorry, forward-port limit can only be set on an origin PR" \
" (%s here) before it's merged and forward-ported." % (
self._get_root().display_name
)
if self.source_id:
msg = "Sorry, forward-port limit can only be set on " \
f"an origin PR ({self.source_id.display_name} " \
"here) before it's merged and forward-ported."
elif self.state in ['merged', 'closed']:
msg = "Sorry, forward-port limit can only be set before the PR is merged."
elif not limit_id:
@ -538,7 +537,7 @@ class PullRequests(models.Model):
if not self:
return
all_sources = [(p.source_id or p._get_root()) for p in self]
all_sources = [(p.source_id or p) for p in self]
all_targets = [s._find_next_target(p) for s, p in zip(all_sources, self)]
ref = self[0]

View File

@ -216,7 +216,7 @@ def test_limit_after_merge(env, config, make_repo, users):
(already forward-ported or not), or is a forward-port PR, fwbot should
just feedback that it won't do it
"""
prod, _ = make_basic(env, config, make_repo)
prod, other = make_basic(env, config, make_repo)
reviewer = config['role_reviewer']['token']
branch_c = env['runbot_merge.branch'].search([('name', '=', 'c')])
bot_name = env['runbot_merge.project'].search([]).fp_github_name
@ -261,3 +261,28 @@ More info at https://github.com/odoo/odoo/wiki/Mergebot#forward-port
" (%s here) before it's merged and forward-ported." % p1.display_name
),
]
# update pr2 to detach it from pr1
with other:
other.make_commits(
p2.target.name,
Commit('updated', tree={'1': '1'}),
ref=pr2.ref,
make=False
)
env.run_crons()
assert not p2.parent_id
assert p2.source_id == p1
with prod:
pr2.post_comment(bot_name + ' up to b', reviewer)
env.run_crons()
assert pr2.comments[4:] == [
(bot_name, "This PR was modified / updated and has become a normal PR. "
"It should be merged the normal way (via @hansen)"),
(users['reviewer'], bot_name + ' up to b'),
(bot_name, "Sorry, forward-port limit can only be set on an origin PR "
f"({p1.display_name} here) before it's merged and forward-ported."
),
]