[FIX] forwardport: fix pinging on forwardport PRs

- avoid pinging the author of the fw PR (which is the forward-bot
  itself)
- instead ping the author and reviewer of the source, and possibly the
  reviewer of the PR if any
- might also be a good idea to ping reviewers of intermediate PRs?
This commit is contained in:
Xavier Morel 2022-11-03 11:46:31 +01:00
parent 5f08100f3a
commit afe4d13eeb
4 changed files with 28 additions and 3 deletions

View File

@ -0,0 +1,3 @@
FIX: stop pinging the forwardbot on forward-port PRs
Also ping the reviewer of the original PR.

View File

@ -1112,6 +1112,22 @@ stderr:
'token_field': 'fp_github_token',
})
def ping(self, author=True, reviewer=True):
source = self.source_id
if not source:
return super().ping(author=author, reviewer=reviewer)
# use a dict literal to maintain ordering (3.6+)
pingline = ' '.join(
f'@{p.github_login}'
for p in filter(None, {
author and source.author: None,
reviewer and source.reviewed_by: None,
reviewer and self.reviewed_by: None,
})
)
return pingline and (pingline + ' ')
class Stagings(models.Model):
_inherit = 'runbot_merge.stagings'

View File

@ -71,7 +71,7 @@ def test_straightforward_flow(env, config, make_repo, users):
# should merge the staging then create the FP PR
env.run_crons()
assert datetime.now() - datetime.strptime(pr_id.merge_date, FMT) <= timedelta(minutes=1),\
assert datetime.utcnow() - datetime.strptime(pr_id.merge_date, FMT) <= timedelta(minutes=1),\
"check if merge date was set about now (within a minute as crons and " \
"RPC calls yield various delays before we're back)"
@ -108,6 +108,12 @@ def test_straightforward_flow(env, config, make_repo, users):
# TODO: add original committer (if !author) as co-author in commit message?
assert c.author['name'] == other_user['user'], "author should still be original's probably"
assert c.committer['name'] == other_user['user'], "committer should also still be the original's, really"
assert pr1.ping() == "@%s @%s " % (
config['role_other']['user'],
config['role_reviewer']['user'],
), "ping of forward-port PR should include author and reviewer of source"
assert prod.read_tree(c) == {
'f': 'c',
'g': 'b',

View File

@ -386,7 +386,7 @@ conflict!
# 2. "forward port chain" bit
# 3. updated / modified & got detached
assert pr2.comments[3:] == [
(users['user'], f"@{users['user']} WARNING: the latest change ({pr2_id.head}) triggered "
(users['user'], f"@{users['user']} @{users['reviewer']} WARNING: the latest change ({pr2_id.head}) triggered "
f"a conflict when updating the next forward-port "
f"({pr3_id.display_name}), and has been ignored.\n\n"
f"You will need to update this pull request "
@ -398,7 +398,7 @@ conflict!
# 2. forward-port chain thing
assert repo.get_pr(pr3_id.number).comments[2:] == [
(users['user'], re_matches(f'''\
@{users['user']} WARNING: the update of {pr2_id.display_name} to {pr2_id.head} has caused a \
@{users['user']} @{users['reviewer']} WARNING: the update of {pr2_id.display_name} to {pr2_id.head} has caused a \
conflict in this pull request, data may have been lost.
stdout: