| 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 781 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 792 | 792 |
| 793 | 793 |
| 794 def _GetRietveldIssueProps(input_api, messages): | 794 def _GetRietveldIssueProps(input_api, messages): |
| 795 """Gets the issue properties from rietveld.""" | 795 """Gets the issue properties from rietveld.""" |
| 796 issue = input_api.change.issue | 796 issue = input_api.change.issue |
| 797 if issue and input_api.rietveld: | 797 if issue and input_api.rietveld: |
| 798 return input_api.rietveld.get_issue_properties( | 798 return input_api.rietveld.get_issue_properties( |
| 799 issue=int(issue), messages=messages) | 799 issue=int(issue), messages=messages) |
| 800 | 800 |
| 801 | 801 |
| 802 def CheckIssueNotClosed(input_api, output_api): | |
| 803 """Verifies issue is not closed. | |
| 804 | |
| 805 We should not be working with a closed review. CQ and dcommit set this bit, | |
| 806 so it is a pretty good indicator of whether an issue has been committed. | |
| 807 """ | |
| 808 issue_props = _GetRietveldIssueProps(input_api=input_api, messages=False) | |
| 809 if issue_props and issue_props['closed']: | |
| 810 return [output_api.PresubmitError( | |
| 811 'Issue %s is closed. You can reset the issue number associated with\n' | |
| 812 'this branch with: git cl issue 0\n' % issue_props['issue'] | |
| 813 )] | |
| 814 return [] | |
| 815 | |
| 816 | |
| 817 def _RietveldOwnerAndReviewers(input_api, email_regexp, approval_needed=False): | 802 def _RietveldOwnerAndReviewers(input_api, email_regexp, approval_needed=False): |
| 818 """Return the owner and reviewers of a change, if any. | 803 """Return the owner and reviewers of a change, if any. |
| 819 | 804 |
| 820 If approval_needed is True, only reviewers who have approved the change | 805 If approval_needed is True, only reviewers who have approved the change |
| 821 will be returned. | 806 will be returned. |
| 822 """ | 807 """ |
| 823 issue_props = _GetRietveldIssueProps(input_api, True) | 808 issue_props = _GetRietveldIssueProps(input_api, True) |
| 824 if not issue_props: | 809 if not issue_props: |
| 825 return None, None | 810 return None, None |
| 826 | 811 |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 955 delta_ms = int(1000*(dt2 - snapshot_memory[0])) | 940 delta_ms = int(1000*(dt2 - snapshot_memory[0])) |
| 956 if delta_ms > 500: | 941 if delta_ms > 500: |
| 957 print " %s took a long time: %dms" % (snapshot_memory[1], delta_ms) | 942 print " %s took a long time: %dms" % (snapshot_memory[1], delta_ms) |
| 958 snapshot_memory[:] = (dt2, msg) | 943 snapshot_memory[:] = (dt2, msg) |
| 959 | 944 |
| 960 if owners_check: | 945 if owners_check: |
| 961 snapshot("checking owners") | 946 snapshot("checking owners") |
| 962 results.extend(input_api.canned_checks.CheckOwners( | 947 results.extend(input_api.canned_checks.CheckOwners( |
| 963 input_api, output_api, source_file_filter=None)) | 948 input_api, output_api, source_file_filter=None)) |
| 964 | 949 |
| 965 snapshot("checking review not closed") | |
| 966 results.extend(input_api.canned_checks.CheckIssueNotClosed( | |
| 967 input_api, output_api)) | |
| 968 | |
| 969 snapshot("checking long lines") | 950 snapshot("checking long lines") |
| 970 results.extend(input_api.canned_checks.CheckLongLines( | 951 results.extend(input_api.canned_checks.CheckLongLines( |
| 971 input_api, output_api, source_file_filter=sources)) | 952 input_api, output_api, source_file_filter=sources)) |
| 972 snapshot( "checking tabs") | 953 snapshot( "checking tabs") |
| 973 results.extend(input_api.canned_checks.CheckChangeHasNoTabs( | 954 results.extend(input_api.canned_checks.CheckChangeHasNoTabs( |
| 974 input_api, output_api, source_file_filter=sources)) | 955 input_api, output_api, source_file_filter=sources)) |
| 975 snapshot( "checking stray whitespace") | 956 snapshot( "checking stray whitespace") |
| 976 results.extend(input_api.canned_checks.CheckChangeHasNoStrayWhitespace( | 957 results.extend(input_api.canned_checks.CheckChangeHasNoStrayWhitespace( |
| 977 input_api, output_api, source_file_filter=sources)) | 958 input_api, output_api, source_file_filter=sources)) |
| 978 snapshot("checking nsobjects") | 959 snapshot("checking nsobjects") |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1000 snapshot("checking description") | 981 snapshot("checking description") |
| 1001 results.extend(input_api.canned_checks.CheckChangeHasDescription( | 982 results.extend(input_api.canned_checks.CheckChangeHasDescription( |
| 1002 input_api, output_api)) | 983 input_api, output_api)) |
| 1003 results.extend(input_api.canned_checks.CheckDoNotSubmitInDescription( | 984 results.extend(input_api.canned_checks.CheckDoNotSubmitInDescription( |
| 1004 input_api, output_api)) | 985 input_api, output_api)) |
| 1005 snapshot("checking do not submit in files") | 986 snapshot("checking do not submit in files") |
| 1006 results.extend(input_api.canned_checks.CheckDoNotSubmitInFiles( | 987 results.extend(input_api.canned_checks.CheckDoNotSubmitInFiles( |
| 1007 input_api, output_api)) | 988 input_api, output_api)) |
| 1008 snapshot("done") | 989 snapshot("done") |
| 1009 return results | 990 return results |
| OLD | NEW |