Repository: rust-lang/homu

Issue:
Ignore commands in quotes
There is another edge case in homu command handling: when an user replies to a comment via email by default the parent command is quoted, and the old parser code tried to handle it. We should ignore commands when the line starts with `>`, to hopefully catch quoted emails, or if the new parser already handles this a test should be added.

Example: https://github.com/rust-lang/rust/pull/61540#issuecomment-504549595

Discussion:

Patch:
diff --git a/homu/parse_issue_comment.py b/homu/parse_issue_comment.py
index ce64c1b..108fbcb 100644
--- a/homu/parse_issue_comment.py
+++ b/homu/parse_issue_comment.py
@@ -158,7 +158,7 @@ def parse_issue_comment(username, body, sha, botname, hooks=[]):
                      re.findall(r'\S+', re.sub(botname_regex, '', x))
                  for x
                  in body.splitlines()
-                 if '@' + botname in x))  # noqa
+                 if '@' + botname in x and not x.lstrip().startswith('>')))  # noqa
 
     commands = []
 


Test patch:
diff --git a/homu/tests/test_parse_issue_comment.py b/homu/tests/test_parse_issue_comment.py
index 34da29f..71a1468 100644
--- a/homu/tests/test_parse_issue_comment.py
+++ b/homu/tests/test_parse_issue_comment.py
@@ -604,3 +604,18 @@ def test_ignore_commands_after_bors_line():
     command = commands[0]
     assert command.action == 'approve'
     assert command.actor == 'jack'
+
+
+def test_in_quote():
+    """
+    Test that a command in a quote (e.g. when replying by e-mail) doesn't
+    trigger.
+    """
+
+    author = "jack"
+    body = """
+    > @bors r+
+    """
+    commands = parse_issue_comment(author, body, commit, "bors")
+
+    assert len(commands) == 0