Skip to content

Commit f5fb2f1

Browse files
committed
Stop parsing when we reach an unknown word
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.
1 parent e885dd7 commit f5fb2f1

File tree

2 files changed

+28
-6
lines changed

2 files changed

+28
-6
lines changed

homu/parse_issue_comment.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -158,13 +158,21 @@ def parse_issue_comment(username, body, sha, botname, hooks=[]):
158158
if words[1:] == ["are", "you", "still", "there?"]:
159159
commands.append(IssueCommentCommand.ping('portal'))
160160

161-
for i, word in reversed(list(enumerate(words))):
162-
found = True
161+
for i, word in enumerate(words):
162+
if word is None:
163+
# We already parsed the next word, and we set it to an empty string
164+
# to signify that we did.
165+
continue
166+
167+
if word == '@' + botname:
168+
continue
169+
163170
if word == 'r+' or word.startswith('r='):
164171
approved_sha = sha
165172

166173
if i + 1 < len(words) and is_sha(words[i + 1]):
167174
approved_sha = words[i + 1]
175+
words[i + 1] = None
168176

169177
approver = word[len('r='):] if word.startswith('r=') else username
170178

@@ -238,9 +246,7 @@ def parse_issue_comment(username, body, sha, botname, hooks=[]):
238246
commands.append(IssueCommentCommand.hook(hook_name, hook_extra))
239247

240248
else:
241-
found = False
242-
243-
if found:
244-
words[i] = ''
249+
# First time we reach an unknown word, stop parsing.
250+
break
245251

246252
return commands

homu/tests/test_parse_issue_comment.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,22 @@ def test_multiple_hooks():
465465
assert thirdhook_commands[0].hook_extra is None
466466

467467

468+
def test_parse_up_to_first_unknown_word():
469+
"""
470+
Test that when parsing, once we arrive at an unknown word, we stop parsing
471+
"""
472+
473+
author = "jack"
474+
body = """
475+
@bors retry -- yielding priority to the rollup
476+
"""
477+
commands = parse_issue_comment(author, body, commit, "bors")
478+
479+
assert len(commands) == 1
480+
command = commands[0]
481+
assert command.action == 'retry'
482+
483+
468484
def test_ignore_commands_before_bors_line():
469485
"""
470486
Test that when command-like statements appear before the @bors part,

0 commit comments

Comments
 (0)