summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rw-r--r--tools/bionicbb/gmail_listener.py11
-rw-r--r--tools/bionicbb/test_gmail_listener.py21
2 files changed, 30 insertions, 2 deletions
diff --git a/tools/bionicbb/gmail_listener.py b/tools/bionicbb/gmail_listener.py
index 455d270..2f19454 100644
--- a/tools/bionicbb/gmail_listener.py
+++ b/tools/bionicbb/gmail_listener.py
@@ -51,6 +51,13 @@ def get_headers(msg):
return headers
+def should_skip_message(gerrit_info):
+ match = re.search(r'<(\S+)>$', gerrit_info['Owner'])
+ if match:
+ return not match.group(1).endswith('@google.com')
+ raise RuntimeError('Gerrit info missing Gerrit-Owner info.')
+
+
def build_service():
from apiclient.discovery import build
from oauth2client.client import flow_from_clientsecrets
@@ -200,7 +207,7 @@ def build_project(gerrit_info, dry_run):
def handle_change(gerrit_info, _, dry_run):
- if '@google.com' not in gerrit_info['Owner']:
+ if should_skip_message(gerrit_info):
return True
return build_project(gerrit_info, dry_run)
handle_newchange = handle_change
@@ -233,7 +240,7 @@ def handle_comment(gerrit_info, body, dry_run):
drop_rejection(gerrit_info, dry_run)
# TODO(danalbert): Needs to be based on the account that made the comment.
- if '@google.com' not in gerrit_info['Owner']:
+ if should_skip_message(gerrit_info):
return True
command_map = {
diff --git a/tools/bionicbb/test_gmail_listener.py b/tools/bionicbb/test_gmail_listener.py
new file mode 100644
index 0000000..feb7961
--- /dev/null
+++ b/tools/bionicbb/test_gmail_listener.py
@@ -0,0 +1,21 @@
+import gmail_listener
+import unittest
+
+
+class TestGerritParsers(unittest.TestCase):
+ def test_should_skip_message(self):
+ info = gmail_listener.get_gerrit_info(
+ 'Gerrit-Owner: Some Googler <somegoogler@google.com>\n')
+ self.assertFalse(gmail_listener.should_skip_message(info))
+
+ info = gmail_listener.get_gerrit_info(
+ 'Gerrit-Owner: Fake Googler <fakegoogler@google.com.foo.com>\n')
+ self.assertTrue(gmail_listener.should_skip_message(info))
+
+ info = gmail_listener.get_gerrit_info(
+ 'Gerrit-Owner: John Doe <johndoe@example.com>\n')
+ self.assertTrue(gmail_listener.should_skip_message(info))
+
+
+if __name__ == '__main__':
+ unittest.main()