[IMP] forwardport: notify when FP PR gets de-parented

If a PR is explicitly updated, it gets converted to a normal
PR[0]. Before this, users had no indication that this had happened and
might be wondering what they're supposed to do (or try to r+ via the
forwardbot, which doesn't work on a root PR).

[0] to an extent: the PR still has a source and might have children,
    in which case the followups will be created from the source &
    existing followups should be updated to match

Closes #206
This commit is contained in:
Xavier Morel 2019-09-23 11:50:21 +02:00
parent 8de6273498
commit 63bef8b7ab
2 changed files with 18 additions and 2 deletions

View File

@ -152,6 +152,7 @@ class PullRequests(models.Model):
# also a bit odd to only handle updating 1 head at a time, but then
# again 2 PRs with same head is weird so...
newhead = vals.get('head')
with_parents = self.filtered('parent_id')
if newhead and not self.env.context.get('ignore_head_update') and newhead != self.head:
vals.setdefault('parent_id', False)
# if any children, this is an FP PR being updated, enqueue
@ -164,12 +165,23 @@ class PullRequests(models.Model):
if vals.get('parent_id') and 'source_id' not in vals:
vals['source_id'] = self.browse(vals['parent_id'])._get_root().id
return super().write(vals)
r = super().write(vals)
if self.env.context.get('forwardport_detach_warn', True):
for p in with_parents:
if not p.parent_id:
self.env['runbot_merge.pull_requests.feedback'].create({
'repository': p.repository.id,
'pull_request': p.number,
'message': "This PR was modified / updated and has become a normal PR. "
"It should be merged the normal way (via @%s)" % p.repository.project_id.github_prefix,
'token_field': 'fp_github_token',
})
return r
def _try_closing(self, by):
r = super()._try_closing(by)
if r:
self.parent_id = False
self.with_context(forwardport_detach_warn=False).parent_id = False
return r
def _parse_commands(self, author, comment, login):

View File

@ -338,6 +338,10 @@ More info at https://github.com/odoo/odoo/wiki/Mergebot#forward-port
assert pr1.head == new_c != pr1_head, "the FP PR should be updated"
assert not pr1.parent_id, "the FP PR should be detached from the original"
assert pr1_remote.comments == [
fp_intermediate, ci_warning, ci_warning,
(users['user'], "This PR was modified / updated and has become a normal PR. It should be merged the normal way (via @%s)" % pr1.repository.project_id.github_prefix),
], "users should be warned that the PR has become non-FP"
# NOTE: should the followup PR wait for pr1 CI or not?
assert pr2.head != pr2_head
assert pr2.parent_id == pr1, "the followup PR should still be linked"