Skip to content

Commit

Permalink
Stop parsing when we reach an unknown word
Browse files Browse the repository at this point in the history
When parsing a @bors command, stop parsing when we reach any unknown
word. This enables commands like

    @bors retry (yielding priority to the rollup)

to include a description of why we retried (which gets put in the retry
log) without also setting `rollup`.

The only tricky bit to this is a command like

    @bors r=person 0123456789abcdef

where the commit sha is part of the `r=` command, and we need to parse
it that way.
  • Loading branch information
bryanburgers committed Jun 12, 2019
1 parent e885dd7 commit 0194c3a
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 6 deletions.
18 changes: 12 additions & 6 deletions homu/parse_issue_comment.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
25 changes: 25 additions & 0 deletions homu/tests/test_parse_issue_comment.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 0194c3a

Please sign in to comment.