diff --git a/presubmit_canned_checks.py b/presubmit_canned_checks.py index 36dd6f9c9..df167e3a8 100644 --- a/presubmit_canned_checks.py +++ b/presubmit_canned_checks.py @@ -106,6 +106,33 @@ def CheckChangeWasUploaded(input_api, output_api): ### Content checks +def CheckAuthorizedAuthor(input_api, output_api): + """For non-googler/chromites committers, verify the author's email address is + in AUTHORS. + """ + author = input_api.change.author_email + if not author: + input_api.logging.info('No author, skipping AUTHOR check') + return [] + authors_path = input_api.os_path.join( + input_api.PresubmitLocalPath(), 'AUTHORS') + valid_authors = ( + input_api.re.match(r'[^#]+\s+\<(.+?)\>\s*$', line) + for line in open(authors_path)) + valid_authors = [item.group(1).lower() for item in valid_authors if item] + if not any(input_api.fnmatch.fnmatch(author.lower(), valid) + for valid in valid_authors): + input_api.logging.info('Valid authors are %s', ', '.join(valid_authors)) + return [output_api.PresubmitPromptWarning( + ('%s is not in AUTHORS file. If you are a new contributor, please visit' + '\n' + 'http://www.chromium.org/developers/contributing-code and read the ' + '"Legal" section\n' + 'If you are a chromite, verify the contributor signed the CLA.') % + author)] + return [] + + def CheckDoNotSubmitInFiles(input_api, output_api): """Checks that the user didn't add 'DO NOT ''SUBMIT' to any files.""" # We want to check every text file, not just source files. diff --git a/tests/presubmit_unittest.py b/tests/presubmit_unittest.py index 51bd22c3b..3f48c9e78 100755 --- a/tests/presubmit_unittest.py +++ b/tests/presubmit_unittest.py @@ -1536,6 +1536,7 @@ class CannedChecksUnittest(PresubmitTestsBase): members = [ 'DEFAULT_LINT_FILTERS', 'BLACKLIST_LINT_FILTERS', + 'CheckAuthorizedAuthor', 'CheckBuildbotPendingBuilds', 'CheckChangeHasBugField', 'CheckChangeHasDescription', 'CheckChangeHasNoStrayWhitespace',