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 _HERE = _os.path.dirname(_os.path.abspath(__file__)) | 8 _HERE = _os.path.dirname(_os.path.abspath(__file__)) |
9 | 9 |
10 | 10 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 """Checks the CL description is not empty.""" | 60 """Checks the CL description is not empty.""" |
61 text = input_api.change.DescriptionText() | 61 text = input_api.change.DescriptionText() |
62 if text.strip() == '': | 62 if text.strip() == '': |
63 if input_api.is_committing: | 63 if input_api.is_committing: |
64 return [output_api.PresubmitError('Add a description.')] | 64 return [output_api.PresubmitError('Add a description.')] |
65 else: | 65 else: |
66 return [output_api.PresubmitNotifyResult('Add a description.')] | 66 return [output_api.PresubmitNotifyResult('Add a description.')] |
67 return [] | 67 return [] |
68 | 68 |
69 | 69 |
70 def CheckChangeDescriptionNotCommitted(input_api, output_api): | |
71 """Checks that the CL does not end with a Committed link.""" | |
72 description = input_api.change.DescriptionText() | |
73 if input_api.re.search('\nCommitted: \S+\s*$', description): | |
74 return [output_api.PresubmitError( | |
75 'The CL description appears to end with a committed link. If this issue\n' | |
76 'has been previously used for a commit, please make a new issue number\n' | |
77 'by typing "git cl issue 0" and reuploading your CL.')] | |
78 return [] | |
79 | |
80 | |
81 def CheckChangeWasUploaded(input_api, output_api): | 70 def CheckChangeWasUploaded(input_api, output_api): |
82 """Checks that the issue was uploaded before committing.""" | 71 """Checks that the issue was uploaded before committing.""" |
83 if input_api.is_committing and not input_api.change.issue: | 72 if input_api.is_committing and not input_api.change.issue: |
84 return [output_api.PresubmitError( | 73 return [output_api.PresubmitError( |
85 'Issue wasn\'t uploaded. Please upload first.')] | 74 'Issue wasn\'t uploaded. Please upload first.')] |
86 return [] | 75 return [] |
87 | 76 |
88 | 77 |
89 ### Content checks | 78 ### Content checks |
90 | 79 |
(...skipping 721 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
812 | 801 |
813 def CheckIssueNotClosed(input_api, output_api): | 802 def CheckIssueNotClosed(input_api, output_api): |
814 """Verifies issue is not closed. | 803 """Verifies issue is not closed. |
815 | 804 |
816 We should not be working with a closed review. CQ and dcommit set this bit, | 805 We should not be working with a closed review. CQ and dcommit set this bit, |
817 so it is a pretty good indicator of whether an issue has been committed. | 806 so it is a pretty good indicator of whether an issue has been committed. |
818 """ | 807 """ |
819 issue_props = _GetRietveldIssueProps(input_api=input_api, messages=False) | 808 issue_props = _GetRietveldIssueProps(input_api=input_api, messages=False) |
820 if issue_props and issue_props['closed']: | 809 if issue_props and issue_props['closed']: |
821 return [output_api.PresubmitError( | 810 return [output_api.PresubmitError( |
822 'Issue %s is closed. If this issue was already used for a commit,\n' | 811 'Issue %s is closed. You can reset the issue number associated with\n' |
823 'please reset the issue number associated with this branch with:\n' | 812 'this branch with: git cl issue 0\n' % issue_props['issue'] |
824 'git cl issue 0\n' % issue_props['issue'] | |
825 )] | 813 )] |
826 return [] | 814 return [] |
827 | 815 |
828 | 816 |
829 def _RietveldOwnerAndReviewers(input_api, email_regexp, approval_needed=False): | 817 def _RietveldOwnerAndReviewers(input_api, email_regexp, approval_needed=False): |
830 """Return the owner and reviewers of a change, if any. | 818 """Return the owner and reviewers of a change, if any. |
831 | 819 |
832 If approval_needed is True, only reviewers who have approved the change | 820 If approval_needed is True, only reviewers who have approved the change |
833 will be returned. | 821 will be returned. |
834 """ | 822 """ |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1007 results.extend(input_api.canned_checks.CheckLicense( | 995 results.extend(input_api.canned_checks.CheckLicense( |
1008 input_api, output_api, license_header, source_file_filter=sources)) | 996 input_api, output_api, license_header, source_file_filter=sources)) |
1009 snapshot("checking was uploaded") | 997 snapshot("checking was uploaded") |
1010 results.extend(input_api.canned_checks.CheckChangeWasUploaded( | 998 results.extend(input_api.canned_checks.CheckChangeWasUploaded( |
1011 input_api, output_api)) | 999 input_api, output_api)) |
1012 snapshot("checking description") | 1000 snapshot("checking description") |
1013 results.extend(input_api.canned_checks.CheckChangeHasDescription( | 1001 results.extend(input_api.canned_checks.CheckChangeHasDescription( |
1014 input_api, output_api)) | 1002 input_api, output_api)) |
1015 results.extend(input_api.canned_checks.CheckDoNotSubmitInDescription( | 1003 results.extend(input_api.canned_checks.CheckDoNotSubmitInDescription( |
1016 input_api, output_api)) | 1004 input_api, output_api)) |
1017 results.extend(input_api.canned_checks.CheckChangeDescriptionNotCommitted( | |
1018 input_api, output_api)) | |
1019 snapshot("checking do not submit in files") | 1005 snapshot("checking do not submit in files") |
1020 results.extend(input_api.canned_checks.CheckDoNotSubmitInFiles( | 1006 results.extend(input_api.canned_checks.CheckDoNotSubmitInFiles( |
1021 input_api, output_api)) | 1007 input_api, output_api)) |
1022 snapshot("done") | 1008 snapshot("done") |
1023 return results | 1009 return results |
OLD | NEW |