Skip to content

Commit

Permalink
Parse homu state out of comments
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bryanburgers committed Jun 12, 2019
1 parent e6d37ee commit 6356b54
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
18 changes: 16 additions & 2 deletions homu/parse_issue_comment.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from itertools import chain
import re
import json

from .consts import WORDS_TO_ROLLUP

Expand Down Expand Up @@ -94,6 +95,12 @@ def hook(cls, hook_name, hook_extra=None):
command.hook_extra = hook_extra
return command

@classmethod
def homu_state(cls, state):
command = cls('homu-state')
command.homu_state = state
return command


def is_sha(sha):
"""
Expand Down Expand Up @@ -144,10 +151,17 @@ 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

commands = []

states = chain.from_iterable(re.findall(r'<!-- homu:(.*?)-->', x)
for x
in body.splitlines())

for state in states:
commands.append(IssueCommentCommand.homu_state(json.loads(state)))

words = list(chain.from_iterable(re.findall(r'\S+', x) for x in body.splitlines() if '@' + botname in x)) # noqa

if words[1:] == ["are", "you", "still", "there?"]:
commands.append(IssueCommentCommand.ping('portal'))

Expand Down
23 changes: 23 additions & 0 deletions homu/tests/test_parse_issue_comment.py
Original file line number Diff line number Diff line change
Expand Up @@ -528,3 +528,26 @@ def test_ignore_commands_after_bors_line():
command = commands[0]
assert command.action == 'approve'
assert command.actor == 'jack'


def test_homu_state():
"""
Test that when a comment has a Homu state in it, we return that state.
"""

author = "bors"
body = """
:hourglass: Trying commit 3d67c2da893aed40bc36b6ac9148c593aa0a868a with merge b7a0ff78ba2ba0b3f5e1a8e89464a84dc386aa81...
<!-- homu: {"type":"TryBuildStarted","head_sha":"3d67c2da893aed40bc36b6ac9148c593aa0a868a","merge_sha":"b7a0ff78ba2ba0b3f5e1a8e89464a84dc386aa81"} -->
""" # noqa

commands = parse_issue_comment(author, body, commit, "bors")

assert len(commands) == 1
command = commands[0]
assert command.action == 'homu-state'
assert command.homu_state == {
'type': 'TryBuildStarted',
'head_sha': '3d67c2da893aed40bc36b6ac9148c593aa0a868a',
'merge_sha': 'b7a0ff78ba2ba0b3f5e1a8e89464a84dc386aa81',
}

0 comments on commit 6356b54

Please sign in to comment.