am 8d50e16a: Merge "Guard against @google.com.example.com."

* commit '8d50e16aa96291612c95f89b49ecfacf556241a6':
  Guard against @google.com.example.com.
This commit is contained in:
Dan Albert 2015-01-12 21:52:52 +00:00 committed by Android Git Automerger
commit d5ff09c23a
2 changed files with 30 additions and 2 deletions

View File

@ -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 = {

View File

@ -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()