OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """Generic presubmit checks that can be reused by other presubmit checks.""" | 6 """Generic presubmit checks that can be reused by other presubmit checks.""" |
7 | 7 |
8 | 8 |
9 ### Description checks | 9 ### Description checks |
10 | 10 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 """Checks that the user didn't add 'DO NOT ' + 'SUBMIT' to the CL description. | 46 """Checks that the user didn't add 'DO NOT ' + 'SUBMIT' to the CL description. |
47 """ | 47 """ |
48 keyword = 'DO NOT ' + 'SUBMIT' | 48 keyword = 'DO NOT ' + 'SUBMIT' |
49 if keyword in input_api.change.DescriptionText(): | 49 if keyword in input_api.change.DescriptionText(): |
50 return [output_api.PresubmitError( | 50 return [output_api.PresubmitError( |
51 keyword + " is present in the changelist description.")] | 51 keyword + " is present in the changelist description.")] |
52 else: | 52 else: |
53 return [] | 53 return [] |
54 | 54 |
55 | 55 |
| 56 def CheckChangeHasDescription(input_api, output_api): |
| 57 """Checks the CL description is not empty.""" |
| 58 text = input_api.change.DescriptionText() |
| 59 if text.strip() == '': |
| 60 if input_api.is_committing: |
| 61 return [output_api.PresubmitError("Add a description.")] |
| 62 else: |
| 63 return [output_api.PresubmitNotifyResult("Add a description.")] |
| 64 return [] |
| 65 |
56 ### Content checks | 66 ### Content checks |
57 | 67 |
58 def CheckDoNotSubmitInFiles(input_api, output_api): | 68 def CheckDoNotSubmitInFiles(input_api, output_api): |
59 """Checks that the user didn't add 'DO NOT ' + 'SUBMIT' to any files.""" | 69 """Checks that the user didn't add 'DO NOT ' + 'SUBMIT' to any files.""" |
60 keyword = 'DO NOT ' + 'SUBMIT' | 70 keyword = 'DO NOT ' + 'SUBMIT' |
61 # We want to check every text files, not just source files. | 71 # We want to check every text files, not just source files. |
62 for f, line_num, line in input_api.RightHandSideLines(lambda x: x): | 72 for f, line_num, line in input_api.RightHandSideLines(lambda x: x): |
63 if keyword in line: | 73 if keyword in line: |
64 text = 'Found ' + keyword + ' in %s, line %s' % (f.LocalPath(), line_num) | 74 text = 'Found ' + keyword + ' in %s, line %s' % (f.LocalPath(), line_num) |
65 return [output_api.PresubmitError(text)] | 75 return [output_api.PresubmitError(text)] |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 long_text=input_api.traceback.format_exc())) | 190 long_text=input_api.traceback.format_exc())) |
181 | 191 |
182 buffer = input_api.cStringIO.StringIO() | 192 buffer = input_api.cStringIO.StringIO() |
183 results = input_api.unittest.TextTestRunner(stream=buffer, verbosity=0).run( | 193 results = input_api.unittest.TextTestRunner(stream=buffer, verbosity=0).run( |
184 input_api.unittest.TestSuite(tests_suite)) | 194 input_api.unittest.TestSuite(tests_suite)) |
185 if not results.wasSuccessful(): | 195 if not results.wasSuccessful(): |
186 outputs.append(message_type("%d unit tests failed." % | 196 outputs.append(message_type("%d unit tests failed." % |
187 (len(results.failures) + len(results.errors)), | 197 (len(results.failures) + len(results.errors)), |
188 long_text=buffer.getvalue())) | 198 long_text=buffer.getvalue())) |
189 return outputs | 199 return outputs |
OLD | NEW |