diff --git a/homu/parse_issue_comment.py b/homu/parse_issue_comment.py index 7fdd3c5..d53c2ea 100644 --- a/homu/parse_issue_comment.py +++ b/homu/parse_issue_comment.py @@ -158,13 +158,21 @@ def parse_issue_comment(username, body, sha, botname, hooks=[]): if words[1:] == ["are", "you", "still", "there?"]: commands.append(IssueCommentCommand.ping('portal')) - for i, word in reversed(list(enumerate(words))): - found = True + for i, word in enumerate(words): + if word is None: + # We already parsed the next word, and we set it to an empty string + # to signify that we did. + continue + + if word == '@' + botname: + continue + if word == 'r+' or word.startswith('r='): approved_sha = sha if i + 1 < len(words) and is_sha(words[i + 1]): approved_sha = words[i + 1] + words[i + 1] = None approver = word[len('r='):] if word.startswith('r=') else username @@ -238,9 +246,7 @@ def parse_issue_comment(username, body, sha, botname, hooks=[]): commands.append(IssueCommentCommand.hook(hook_name, hook_extra)) else: - found = False - - if found: - words[i] = '' + # First time we reach an unknown word, stop parsing. + break return commands diff --git a/homu/tests/test_parse_issue_comment.py b/homu/tests/test_parse_issue_comment.py index 3db4a77..5525b26 100644 --- a/homu/tests/test_parse_issue_comment.py +++ b/homu/tests/test_parse_issue_comment.py @@ -465,6 +465,31 @@ def test_multiple_hooks(): assert thirdhook_commands[0].hook_extra is None +def test_parse_up_to_first_unknown_word(): + """ + Test that when parsing, once we arrive at an unknown word, we stop parsing + """ + + author = "jack" + body = """ + @bors retry -- yielding priority to the rollup + """ + commands = parse_issue_comment(author, body, commit, "bors") + + assert len(commands) == 1 + command = commands[0] + assert command.action == 'retry' + + body = """ + @bors retry (yielding priority to the rollup) + """ + commands = parse_issue_comment(author, body, commit, "bors") + + assert len(commands) == 1 + command = commands[0] + assert command.action == 'retry' + + def test_ignore_commands_before_bors_line(): """ Test that when command-like statements appear before the @bors part,