From dc435f6b138f0bcfed70b5deaacbf173d7dd48f0 Mon Sep 17 00:00:00 2001 From: Bryan Burgers Date: Wed, 12 Jun 2019 16:01:52 -0500 Subject: [PATCH] Make sure Homu hidden approval command parses Homu leaves self-approvals in comments, like and we need to make sure those still parse correctly. --- homu/parse_issue_comment.py | 9 ++++++++- homu/tests/test_parse_issue_comment.py | 16 ++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/homu/parse_issue_comment.py b/homu/parse_issue_comment.py index d53c2ea..e43133f 100644 --- a/homu/parse_issue_comment.py +++ b/homu/parse_issue_comment.py @@ -151,7 +151,14 @@ def parse_issue_comment(username, body, sha, botname, hooks=[]): E.g. `['hook1', 'hook2', 'hook3']` """ - words = list(chain.from_iterable(re.findall(r'\S+', x) for x in body.splitlines() if '@' + botname in x)) # noqa + botname_regex = re.compile(r'^.*(?=@' + botname + ')') + + # All of the 'words' after and including the botname + words = list(chain.from_iterable( + re.findall(r'\S+', re.sub(botname_regex, '', x)) + for x + in body.splitlines() + if '@' + botname in x)) # noqa commands = [] diff --git a/homu/tests/test_parse_issue_comment.py b/homu/tests/test_parse_issue_comment.py index 5525b26..e7e475a 100644 --- a/homu/tests/test_parse_issue_comment.py +++ b/homu/tests/test_parse_issue_comment.py @@ -52,6 +52,22 @@ def test_r_equals(): assert command.actor == 'jill' +def test_hidden_r_equals(): + author = "bors" + body = """ + :pushpin: Commit {0} has been approved by `jack` + + """.format(commit) + + commands = parse_issue_comment(author, body, commit, "bors") + + assert len(commands) == 1 + command = commands[0] + assert command.action == 'approve' + assert command.actor == 'jack' + assert command.commit == commit + + def test_r_me(): """ Ignore r=me