From 6356b549c23b8c1458f5c6f52730d87d9a8569b7 Mon Sep 17 00:00:00 2001 From: Bryan Burgers Date: Fri, 7 Jun 2019 10:26:38 -0500 Subject: [PATCH] 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. :hourglass: Trying commit abcdef with merge 012345... This change parses this extra information out of the comments and makes it available to the initial synchronization algorithm. --- homu/parse_issue_comment.py | 18 ++++++++++++++++-- homu/tests/test_parse_issue_comment.py | 23 +++++++++++++++++++++++ 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/homu/parse_issue_comment.py b/homu/parse_issue_comment.py index 9f7f1e4..9a24147 100644 --- a/homu/parse_issue_comment.py +++ b/homu/parse_issue_comment.py @@ -1,5 +1,6 @@ from itertools import chain import re +import json from .consts import WORDS_TO_ROLLUP @@ -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): """ @@ -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'', 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')) diff --git a/homu/tests/test_parse_issue_comment.py b/homu/tests/test_parse_issue_comment.py index 5525b26..cc75696 100644 --- a/homu/tests/test_parse_issue_comment.py +++ b/homu/tests/test_parse_issue_comment.py @@ -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... + + """ # 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', + }