From bb664455ec5b0a3f1d1f03b8827e78357cd61800 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Fri, 21 Sep 2018 10:27:07 +0200 Subject: [PATCH] [IMP] runbot_merge: allow invoking bot as @bot and #bot Before this, the bot would only acknowledge commands of the form : but since the bot is an actual user, people regularly use `@` as it seems like it should work *and* provides for autocompletion. Support that, as well as the octothorpe in case users want to pound robodoo. Related to odoo/runbot#38 --- runbot_merge/models/pull_requests.py | 4 ++-- runbot_merge/tests/test_basic.py | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/runbot_merge/models/pull_requests.py b/runbot_merge/models/pull_requests.py index f0ec3783..9dcfbed9 100644 --- a/runbot_merge/models/pull_requests.py +++ b/runbot_merge/models/pull_requests.py @@ -214,7 +214,7 @@ class Project(models.Model): # temp hack: add a delay between staging repositories # in case there's a race when quickly pushing a repo # then its dependency - time.sleep(20) + # time.sleep(20) # creating the staging doesn't trigger a write on the prs # and thus the ->staging taggings, so do that by hand @@ -284,7 +284,7 @@ class Project(models.Model): def _find_commands(self, comment): return re.findall( - '^{}:? (.*)$'.format(self.github_prefix), + '^[@|#]?{}:? (.*)$'.format(self.github_prefix), comment, re.MULTILINE) def _has_branch(self, name): diff --git a/runbot_merge/tests/test_basic.py b/runbot_merge/tests/test_basic.py index aa446acb..e85d7109 100644 --- a/runbot_merge/tests/test_basic.py +++ b/runbot_merge/tests/test_basic.py @@ -1747,6 +1747,28 @@ class TestUnknownPR: env['runbot_merge.project']._check_progress() assert pr.staging_id +class TestComments: + def test_address_method(self, repo, env): + m = repo.make_commit(None, 'initial', None, tree={'m': 'm'}) + repo.make_ref('heads/master', m) + + c1 = repo.make_commit(m, 'first', None, tree={'m': 'c1'}) + prx = repo.make_pr('title', 'body', target='master', ctid=c1, user='user') + + repo.post_status(prx.head, 'success', 'legal/cla') + repo.post_status(prx.head, 'success', 'ci/runbot') + prx.post_comment('hansen delegate=foo', user='reviewer') + prx.post_comment('@hansen delegate=bar', user='reviewer') + prx.post_comment('#hansen delegate=baz', user='reviewer') + + pr = env['runbot_merge.pull_requests'].search([ + ('repository.name', '=', repo.name), + ('number', '=', prx.number) + ]) + + assert {p.github_login for p in pr.delegates} \ + == {'foo', 'bar', 'baz'} + def node(name, *children): assert type(name) in (str, re_matches) return name, frozenset(children)