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

Side by Side Diff: presubmit_canned_checks.py

Issue 11348122: Add presubmit check to verify issue is not closed. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Created 8 years 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | tests/presubmit_unittest.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 773 matching lines...) Expand 10 before | Expand all | Expand 10 after
784 suggested_owners = owners_db.reviewers_for(affected_files) 784 suggested_owners = owners_db.reviewers_for(affected_files)
785 output_list.append(output('Suggested OWNERS:\n %s' % 785 output_list.append(output('Suggested OWNERS:\n %s' %
786 ('\n '.join(suggested_owners)))) 786 ('\n '.join(suggested_owners))))
787 return output_list 787 return output_list
788 788
789 if input_api.is_committing and not reviewers: 789 if input_api.is_committing and not reviewers:
790 return [output('Missing LGTM from someone other than %s' % owner_email)] 790 return [output('Missing LGTM from someone other than %s' % owner_email)]
791 return [] 791 return []
792 792
793 793
794 def _GetRietveldIssueProps(input_api, messages):
795 """Gets the issue properties from rietveld."""
796 issue = input_api.change.issue
797 if issue and input_api.rietveld:
798 return input_api.rietveld.get_issue_properties(
799 issue=int(issue), messages=messages)
800
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. If this issue was already used for a commit,\n'
812 'please reset the issue number associated with this branch with:\n'
813 'git cl issue 0\n' % issue_props['issue']
814 )]
815 return []
816
817
794 def _RietveldOwnerAndReviewers(input_api, email_regexp, approval_needed=False): 818 def _RietveldOwnerAndReviewers(input_api, email_regexp, approval_needed=False):
795 """Return the owner and reviewers of a change, if any. 819 """Return the owner and reviewers of a change, if any.
796 820
797 If approval_needed is True, only reviewers who have approved the change 821 If approval_needed is True, only reviewers who have approved the change
798 will be returned. 822 will be returned.
799 """ 823 """
800 if not input_api.change.issue: 824 issue_props = _GetRietveldIssueProps(input_api, True)
825 if not issue_props:
801 return None, None 826 return None, None
802 827
803 issue_props = input_api.rietveld.get_issue_properties(
804 int(input_api.change.issue), True)
805 if not approval_needed: 828 if not approval_needed:
806 return issue_props['owner_email'], set(issue_props['reviewers']) 829 return issue_props['owner_email'], set(issue_props['reviewers'])
807 830
808 owner_email = issue_props['owner_email'] 831 owner_email = issue_props['owner_email']
809 832
810 def match_reviewer(r): 833 def match_reviewer(r):
811 return email_regexp.match(r) and r != owner_email 834 return email_regexp.match(r) and r != owner_email
812 835
813 messages = issue_props.get('messages', []) 836 messages = issue_props.get('messages', [])
814 approvers = set( 837 approvers = set(
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
933 delta_ms = int(1000*(dt2 - snapshot_memory[0])) 956 delta_ms = int(1000*(dt2 - snapshot_memory[0]))
934 if delta_ms > 500: 957 if delta_ms > 500:
935 print " %s took a long time: %dms" % (snapshot_memory[1], delta_ms) 958 print " %s took a long time: %dms" % (snapshot_memory[1], delta_ms)
936 snapshot_memory[:] = (dt2, msg) 959 snapshot_memory[:] = (dt2, msg)
937 960
938 if owners_check: 961 if owners_check:
939 snapshot("checking owners") 962 snapshot("checking owners")
940 results.extend(input_api.canned_checks.CheckOwners( 963 results.extend(input_api.canned_checks.CheckOwners(
941 input_api, output_api, source_file_filter=None)) 964 input_api, output_api, source_file_filter=None))
942 965
966 snapshot("checking review not closed")
967 results.extend(input_api.canned_checks.CheckIssueNotClosed(
968 input_api, output_api))
969
943 snapshot("checking long lines") 970 snapshot("checking long lines")
944 results.extend(input_api.canned_checks.CheckLongLines( 971 results.extend(input_api.canned_checks.CheckLongLines(
945 input_api, output_api, source_file_filter=sources)) 972 input_api, output_api, source_file_filter=sources))
946 snapshot( "checking tabs") 973 snapshot( "checking tabs")
947 results.extend(input_api.canned_checks.CheckChangeHasNoTabs( 974 results.extend(input_api.canned_checks.CheckChangeHasNoTabs(
948 input_api, output_api, source_file_filter=sources)) 975 input_api, output_api, source_file_filter=sources))
949 snapshot( "checking stray whitespace") 976 snapshot( "checking stray whitespace")
950 results.extend(input_api.canned_checks.CheckChangeHasNoStrayWhitespace( 977 results.extend(input_api.canned_checks.CheckChangeHasNoStrayWhitespace(
951 input_api, output_api, source_file_filter=sources)) 978 input_api, output_api, source_file_filter=sources))
952 snapshot("checking nsobjects") 979 snapshot("checking nsobjects")
(...skipping 13 matching lines...) Expand all
966 results.extend(input_api.canned_checks.CheckSvnForCommonMimeTypes( 993 results.extend(input_api.canned_checks.CheckSvnForCommonMimeTypes(
967 input_api, output_api)) 994 input_api, output_api))
968 snapshot("checking license") 995 snapshot("checking license")
969 results.extend(input_api.canned_checks.CheckLicense( 996 results.extend(input_api.canned_checks.CheckLicense(
970 input_api, output_api, license_header, source_file_filter=sources)) 997 input_api, output_api, license_header, source_file_filter=sources))
971 snapshot("checking was uploaded") 998 snapshot("checking was uploaded")
972 results.extend(input_api.canned_checks.CheckChangeWasUploaded( 999 results.extend(input_api.canned_checks.CheckChangeWasUploaded(
973 input_api, output_api)) 1000 input_api, output_api))
974 snapshot("done") 1001 snapshot("done")
975 return results 1002 return results
OLDNEW
« no previous file with comments | « no previous file | tests/presubmit_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698