[FIX] runbot_merge: less restrictive commands matching

Fixes #167 ignores casing when matching bot name
Fixes #168 ignores leading whitespace when matching commands lines
This commit is contained in:
xmo-odoo 2019-08-26 13:41:33 +02:00 committed by GitHub
parent 8b74e79da9
commit 02d85ad523
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 43 additions and 2 deletions

View File

@ -165,8 +165,8 @@ class Project(models.Model):
def _find_commands(self, comment):
return re.findall(
'^[@|#]?{}:? (.*)$'.format(self.github_prefix),
comment, re.MULTILINE)
'^\s*[@|#]?{}:? (.*)$'.format(self.github_prefix),
comment, re.MULTILINE | re.IGNORECASE)
def _has_branch(self, name):
self.env.cr.execute("""

View File

@ -2336,6 +2336,47 @@ class TestUnknownPR:
(users['user'], "I'm sorry. Branch `branch` is not within my remit."),
]
class TestRecognizeCommands:
@pytest.mark.parametrize('botname', ['hansen', 'Hansen', 'HANSEN', 'HanSen', 'hAnSeN'])
def test_botname_casing(self, repo, env, botname):
""" Test that the botname is case-insensitive as people might write
bot names capitalised or titlecased or uppercased or whatever
"""
m = repo.make_commit(None, 'initial', None, tree={'m': 'm'})
repo.make_ref('heads/master', m)
c = repo.make_commit(m, 'first', None, tree={'m': 'c'})
prx = repo.make_pr('title', None, target='master', ctid=c, user='user')
pr = env['runbot_merge.pull_requests'].search([
('repository.name', '=', repo.name),
('number', '=', prx.number),
])
assert pr.state == 'opened'
prx.post_comment('%s r+' % botname, 'reviewer')
assert pr.state == 'approved'
@pytest.mark.parametrize('indent', ['', '\N{SPACE}', '\N{SPACE}'*4, '\N{TAB}'])
def test_botname_indented(self, repo, env, indent):
""" matching botname should ignore leading whitespaces
"""
m = repo.make_commit(None, 'initial', None, tree={'m': 'm'})
repo.make_ref('heads/master', m)
c = repo.make_commit(m, 'first', None, tree={'m': 'c'})
prx = repo.make_pr('title', None, target='master', ctid=c, user='user')
pr = env['runbot_merge.pull_requests'].search([
('repository.name', '=', repo.name),
('number', '=', prx.number),
])
assert pr.state == 'opened'
prx.post_comment('%shansen r+' % indent, 'reviewer')
assert pr.state == 'approved'
class TestRMinus:
def test_rminus_approved(self, repo, env):
""" approved -> r- -> opened