Skip to content

Commit 6356b54

Browse files
committed
Parse homu state out of comments
For some critical comments, Homu adds extra information about its state in the form of a JSON blob to the comment that isn't visible to the user but is visible in the source for the comment. For example, Homu may leave a comment like the following, where the JSON blob is not visible because of the `<!-- .. -->` markdown/html comments. ⌛ Trying commit abcdef with merge 012345... <!-- homu: {"type":"TryBuildStarted","head_sha":"abcdef","merge_sha":"012345"} --> This change parses this extra information out of the comments and makes it available to the initial synchronization algorithm.
1 parent e6d37ee commit 6356b54

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed

homu/parse_issue_comment.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from itertools import chain
22
import re
3+
import json
34

45
from .consts import WORDS_TO_ROLLUP
56

@@ -94,6 +95,12 @@ def hook(cls, hook_name, hook_extra=None):
9495
command.hook_extra = hook_extra
9596
return command
9697

98+
@classmethod
99+
def homu_state(cls, state):
100+
command = cls('homu-state')
101+
command.homu_state = state
102+
return command
103+
97104

98105
def is_sha(sha):
99106
"""
@@ -144,10 +151,17 @@ def parse_issue_comment(username, body, sha, botname, hooks=[]):
144151
E.g. `['hook1', 'hook2', 'hook3']`
145152
"""
146153

147-
words = list(chain.from_iterable(re.findall(r'\S+', x) for x in body.splitlines() if '@' + botname in x)) # noqa
148-
149154
commands = []
150155

156+
states = chain.from_iterable(re.findall(r'<!-- homu:(.*?)-->', x)
157+
for x
158+
in body.splitlines())
159+
160+
for state in states:
161+
commands.append(IssueCommentCommand.homu_state(json.loads(state)))
162+
163+
words = list(chain.from_iterable(re.findall(r'\S+', x) for x in body.splitlines() if '@' + botname in x)) # noqa
164+
151165
if words[1:] == ["are", "you", "still", "there?"]:
152166
commands.append(IssueCommentCommand.ping('portal'))
153167

homu/tests/test_parse_issue_comment.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,3 +528,26 @@ def test_ignore_commands_after_bors_line():
528528
command = commands[0]
529529
assert command.action == 'approve'
530530
assert command.actor == 'jack'
531+
532+
533+
def test_homu_state():
534+
"""
535+
Test that when a comment has a Homu state in it, we return that state.
536+
"""
537+
538+
author = "bors"
539+
body = """
540+
:hourglass: Trying commit 3d67c2da893aed40bc36b6ac9148c593aa0a868a with merge b7a0ff78ba2ba0b3f5e1a8e89464a84dc386aa81...
541+
<!-- homu: {"type":"TryBuildStarted","head_sha":"3d67c2da893aed40bc36b6ac9148c593aa0a868a","merge_sha":"b7a0ff78ba2ba0b3f5e1a8e89464a84dc386aa81"} -->
542+
""" # noqa
543+
544+
commands = parse_issue_comment(author, body, commit, "bors")
545+
546+
assert len(commands) == 1
547+
command = commands[0]
548+
assert command.action == 'homu-state'
549+
assert command.homu_state == {
550+
'type': 'TryBuildStarted',
551+
'head_sha': '3d67c2da893aed40bc36b6ac9148c593aa0a868a',
552+
'merge_sha': 'b7a0ff78ba2ba0b3f5e1a8e89464a84dc386aa81',
553+
}

0 commit comments

Comments
 (0)