Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 """Generic presubmit checks that can be reused by other presubmit checks.""" | 5 """Generic presubmit checks that can be reused by other presubmit checks.""" |
| 6 | 6 |
| 7 import os as _os | 7 import os as _os |
| 8 import re | |
|
M-A Ruel
2012/11/22 15:47:06
why not input_api.re?
Isaac (away)
2012/11/22 18:50:52
I can do that -- is there a reason we're avoiding
Dirk Pranke
2012/11/22 18:54:07
input_api.re would just be a pointer to the python
Isaac (away)
2012/11/25 02:12:44
OK, fixed.
| |
| 9 | |
| 8 _HERE = _os.path.dirname(_os.path.abspath(__file__)) | 10 _HERE = _os.path.dirname(_os.path.abspath(__file__)) |
| 9 | 11 |
| 10 | 12 |
| 11 ### Description checks | 13 ### Description checks |
| 12 | 14 |
| 13 def CheckChangeHasTestField(input_api, output_api): | 15 def CheckChangeHasTestField(input_api, output_api): |
| 14 """Requires that the changelist have a TEST= field.""" | 16 """Requires that the changelist have a TEST= field.""" |
| 15 if input_api.change.TEST: | 17 if input_api.change.TEST: |
| 16 return [] | 18 return [] |
| 17 else: | 19 else: |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 39 | 41 |
| 40 def CheckChangeHasQaField(input_api, output_api): | 42 def CheckChangeHasQaField(input_api, output_api): |
| 41 """Requires that the changelist have a QA= field.""" | 43 """Requires that the changelist have a QA= field.""" |
| 42 if input_api.change.QA: | 44 if input_api.change.QA: |
| 43 return [] | 45 return [] |
| 44 else: | 46 else: |
| 45 return [output_api.PresubmitError('Changelist must have a QA= field.')] | 47 return [output_api.PresubmitError('Changelist must have a QA= field.')] |
| 46 | 48 |
| 47 | 49 |
| 48 def CheckDoNotSubmitInDescription(input_api, output_api): | 50 def CheckDoNotSubmitInDescription(input_api, output_api): |
| 49 """Checks that the user didn't add 'DO NOT ' + 'SUBMIT' to the CL description. | 51 """Checks that the user didn't add 'DO NOT SUBMIT' to the CL description. |
|
M-A Ruel
2012/11/22 15:47:06
Why? This would block the CQ from processing this
Isaac (away)
2012/11/22 18:50:52
I didn't realize that was the reason for splitting
Isaac (away)
2012/11/25 02:12:44
Fixed.
| |
| 50 """ | 52 """ |
| 51 keyword = 'DO NOT ' + 'SUBMIT' | 53 keyword = 'DO NOT SUBMIT' |
| 52 if keyword in input_api.change.DescriptionText(): | 54 if keyword in input_api.change.DescriptionText(): |
| 53 return [output_api.PresubmitError( | 55 return [output_api.PresubmitError( |
| 54 keyword + ' is present in the changelist description.')] | 56 keyword + ' is present in the changelist description.')] |
| 55 else: | 57 else: |
| 56 return [] | 58 return [] |
| 57 | 59 |
| 58 | 60 |
| 59 def CheckChangeHasDescription(input_api, output_api): | 61 def CheckChangeHasDescription(input_api, output_api): |
| 60 """Checks the CL description is not empty.""" | 62 """Checks the CL description is not empty.""" |
| 61 text = input_api.change.DescriptionText() | 63 text = input_api.change.DescriptionText() |
| 62 if text.strip() == '': | 64 if text.strip() == '': |
| 63 if input_api.is_committing: | 65 if input_api.is_committing: |
| 64 return [output_api.PresubmitError('Add a description.')] | 66 return [output_api.PresubmitError('Add a description.')] |
| 65 else: | 67 else: |
| 66 return [output_api.PresubmitNotifyResult('Add a description.')] | 68 return [output_api.PresubmitNotifyResult('Add a description.')] |
| 67 return [] | 69 return [] |
| 68 | 70 |
| 69 | 71 |
| 72 def CheckChangeDescriptionNotCommitted(input_api, output_api): | |
| 73 """Checks that the CL does not end with a Committed link.""" | |
| 74 description = input_api.change.DescriptionText() | |
| 75 if re.match('\nCommitted: \S+$', description): | |
|
M-A Ruel
2012/11/22 15:47:06
You could use ^ instead with re.search(.., re.MULT
Isaac (away)
2012/11/22 18:50:52
I only want to match Committed on the last line, s
| |
| 76 return [output_api.PresubmitError( | |
| 77 'The CL description appears to end with a committed link. If this issue\n' | |
| 78 'has been previously used for a commit, please make a new issue number\n' | |
| 79 'by typing "git cl issue 0" and reuploading your CL.')] | |
| 80 return [] | |
| 81 | |
| 82 | |
| 70 def CheckChangeWasUploaded(input_api, output_api): | 83 def CheckChangeWasUploaded(input_api, output_api): |
| 71 """Checks that the issue was uploaded before committing.""" | 84 """Checks that the issue was uploaded before committing.""" |
| 72 if input_api.is_committing and not input_api.change.issue: | 85 if input_api.is_committing and not input_api.change.issue: |
| 73 return [output_api.PresubmitError( | 86 return [output_api.PresubmitError( |
| 74 'Issue wasn\'t uploaded. Please upload first.')] | 87 'Issue wasn\'t uploaded. Please upload first.')] |
| 75 return [] | 88 return [] |
| 76 | 89 |
| 77 | 90 |
| 78 ### Content checks | 91 ### Content checks |
| 79 | 92 |
| 80 def CheckDoNotSubmitInFiles(input_api, output_api): | 93 def CheckDoNotSubmitInFiles(input_api, output_api): |
| 81 """Checks that the user didn't add 'DO NOT ' + 'SUBMIT' to any files.""" | 94 """Checks that the user didn't add 'DO NOT SUBMIT' to any files.""" |
| 82 # We want to check every text file, not just source files. | 95 # We want to check every text file, not just source files. |
| 83 file_filter = lambda x : x | 96 file_filter = lambda x : x |
| 84 keyword = 'DO NOT ' + 'SUBMIT' | 97 keyword = 'DO NOT SUBMIT' |
| 85 errors = _FindNewViolationsOfRule(lambda _, line : keyword not in line, | 98 errors = _FindNewViolationsOfRule(lambda _, line : keyword not in line, |
| 86 input_api, file_filter) | 99 input_api, file_filter) |
| 87 text = '\n'.join('Found %s in %s' % (keyword, loc) for loc in errors) | 100 text = '\n'.join('Found %s in %s' % (keyword, loc) for loc in errors) |
| 88 if text: | 101 if text: |
| 89 return [output_api.PresubmitError(text)] | 102 return [output_api.PresubmitError(text)] |
| 90 return [] | 103 return [] |
| 91 | 104 |
| 92 | 105 |
| 93 def CheckChangeLintsClean(input_api, output_api, source_file_filter=None): | 106 def CheckChangeLintsClean(input_api, output_api, source_file_filter=None): |
| 94 """Checks that all '.cc' and '.h' files pass cpplint.py.""" | 107 """Checks that all '.cc' and '.h' files pass cpplint.py.""" |
| (...skipping 869 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 964 input_api, output_api, source_file_filter=text_files)) | 977 input_api, output_api, source_file_filter=text_files)) |
| 965 snapshot("checking svn mime types") | 978 snapshot("checking svn mime types") |
| 966 results.extend(input_api.canned_checks.CheckSvnForCommonMimeTypes( | 979 results.extend(input_api.canned_checks.CheckSvnForCommonMimeTypes( |
| 967 input_api, output_api)) | 980 input_api, output_api)) |
| 968 snapshot("checking license") | 981 snapshot("checking license") |
| 969 results.extend(input_api.canned_checks.CheckLicense( | 982 results.extend(input_api.canned_checks.CheckLicense( |
| 970 input_api, output_api, license_header, source_file_filter=sources)) | 983 input_api, output_api, license_header, source_file_filter=sources)) |
| 971 snapshot("checking was uploaded") | 984 snapshot("checking was uploaded") |
| 972 results.extend(input_api.canned_checks.CheckChangeWasUploaded( | 985 results.extend(input_api.canned_checks.CheckChangeWasUploaded( |
| 973 input_api, output_api)) | 986 input_api, output_api)) |
| 987 snapshot("checking description") | |
| 988 results.extend(input_api.canned_checks.CheckChangeHasDescription( | |
| 989 input_api, output_api)) | |
| 990 results.extend(input_api.canned_checks.CheckDoNotSubmitInDescription( | |
| 991 input_api, output_api)) | |
| 992 results.extend(input_api.canned_checks.CheckChangeDescriptionNotCommitted( | |
| 993 input_api, output_api)) | |
| 994 snapshot("checking do not submit in files") | |
| 995 results.extend(input_api.canned_checks.CheckDoNotSubmitInFiles( | |
| 996 input_api, output_api)) | |
| 974 snapshot("done") | 997 snapshot("done") |
| 975 return results | 998 return results |
| OLD | NEW |