Check author of a CL against the AUTHORS file.
authormarja <marja@chromium.org>
Thu, 15 Jan 2015 13:10:01 +0000 (05:10 -0800)
committerCommit bot <commit-bot@chromium.org>
Thu, 15 Jan 2015 13:10:09 +0000 (13:10 +0000)
The code is copied from Chromium presubmit.

BUG=

Review URL: https://codereview.chromium.org/837503003

Cr-Commit-Position: refs/heads/master@{#26077}

PRESUBMIT.py
tools/presubmit.py

index 6d19a4e..2ab45ad 100644 (file)
@@ -69,6 +69,7 @@ def _V8PresubmitChecks(input_api, output_api):
   from presubmit import SourceProcessor
   from presubmit import CheckRuntimeVsNativesNameClashes
   from presubmit import CheckExternalReferenceRegistration
+  from presubmit import CheckAuthorizedAuthor
 
   results = []
   if not CppLintProcessor().Run(input_api.PresubmitLocalPath()):
@@ -83,6 +84,7 @@ def _V8PresubmitChecks(input_api, output_api):
   if not CheckExternalReferenceRegistration(input_api.PresubmitLocalPath()):
     results.append(output_api.PresubmitError(
         "External references registration check failed"))
+  results.extend(CheckAuthorizedAuthor(input_api, output_api))
   return results
 
 
index 321d291..97b3b59 100755 (executable)
@@ -438,6 +438,33 @@ def CheckExternalReferenceRegistration(workspace):
       [sys.executable, join(workspace, "tools", "external-reference-check.py")])
   return code == 0
 
+def CheckAuthorizedAuthor(input_api, output_api):
+  """For non-googler/chromites committers, verify the author's email address is
+  in AUTHORS.
+  """
+  # TODO(maruel): Add it to input_api?
+  import fnmatch
+
+  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(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 GetOptions():
   result = optparse.OptionParser()