Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(108)

Unified Diff: PRESUBMIT.py

Issue 1003363005: Add presubmit check for copyright notice (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Skip third_party Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: PRESUBMIT.py
diff --git a/PRESUBMIT.py b/PRESUBMIT.py
index ae5a2183162c81026e8e382e6792b75fe362cc8c..9abe70f727900d6e40dc2d680adf5ddfc84c7be4 100644
--- a/PRESUBMIT.py
+++ b/PRESUBMIT.py
@@ -118,6 +118,24 @@ def _IfDefChecks(input_api, output_api):
return results
+def _CopyrightChecks(input_api, output_api, source_file_filter=None):
+ results = []
+ year_pattern = r'\d{4}'
+ year_range_pattern = r'%s(-%s)?' % (year_pattern, year_pattern)
+ years_pattern = r'%s(,%s)*,?' % (year_range_pattern, year_range_pattern)
+ copyright_pattern = (
+ r'Copyright (\([cC]\) )?%s \w+' % years_pattern)
+
+ for affected_file in input_api.AffectedSourceFiles(source_file_filter):
+ if 'third_party' in affected_file.LocalPath():
+ continue
+ contents = input_api.ReadFile(affected_file, 'rb')
+ if not re.search(copyright_pattern, contents):
+ results.append(output_api.PresubmitError(
+ '%s is missing a correct copyright header.' % affected_file))
+ return results
+
+
def _CommonChecks(input_api, output_api):
"""Presubmit checks common to upload and commit."""
results = []
@@ -132,6 +150,8 @@ def _CommonChecks(input_api, output_api):
input_api, output_api, source_file_filter=sources))
results.extend(_PythonChecks(input_api, output_api))
results.extend(_IfDefChecks(input_api, output_api))
+ results.extend(_CopyrightChecks(input_api, output_api,
+ source_file_filter=sources))
return results
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698