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

Side by Side Diff: presubmit_canned_checks.py

Issue 7058025: Switch CheckOwners to use input_api.rietveld. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Fix it for real this time Created 9 years, 6 months 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 | rietveld.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) 2010 The Chromium Authors. All rights reserved. 1 # Copyright (c) 2010 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 7
8 ### Description checks 8 ### Description checks
9 9
10 def CheckChangeHasTestField(input_api, output_api): 10 def CheckChangeHasTestField(input_api, output_api):
(...skipping 723 matching lines...) Expand 10 before | Expand all | Expand 10 after
734 return [output_api.PresubmitError( 734 return [output_api.PresubmitError(
735 "OWNERS check failed: this change has no Rietveld issue number, so " 735 "OWNERS check failed: this change has no Rietveld issue number, so "
736 "we can't check it for approvals.")] 736 "we can't check it for approvals.")]
737 737
738 affected_files = set([f.LocalPath() for f in 738 affected_files = set([f.LocalPath() for f in
739 input_api.change.AffectedFiles(file_filter=source_file_filter)]) 739 input_api.change.AffectedFiles(file_filter=source_file_filter)])
740 740
741 owners_db = input_api.owners_db 741 owners_db = input_api.owners_db
742 owner_email, approvers = _RietveldOwnerAndApprovers(input_api, 742 owner_email, approvers = _RietveldOwnerAndApprovers(input_api,
743 owners_db.email_regexp) 743 owners_db.email_regexp)
744 if not owner_email:
745 return [output_api.PresubmitWarning(
746 'The issue was not uploaded so you have no OWNER approval.')]
747
744 approvers_plus_owner = approvers.union(set([owner_email])) 748 approvers_plus_owner = approvers.union(set([owner_email]))
745 749
746 missing_files = owners_db.files_not_covered_by(affected_files, 750 missing_files = owners_db.files_not_covered_by(affected_files,
747 approvers_plus_owner) 751 approvers_plus_owner)
748 if missing_files: 752 if missing_files:
749 return [output_api.PresubmitError('Missing LGTM from an OWNER for: %s' % 753 return [output_api.PresubmitError('Missing LGTM from an OWNER for: %s' %
750 ','.join(missing_files))] 754 ','.join(missing_files))]
751 755
752 if not approvers: 756 if not approvers:
753 return [output_api.PresubmitError('Missing LGTM from someone other than %s' 757 return [output_api.PresubmitError('Missing LGTM from someone other than %s'
754 % owner_email)] 758 % owner_email)]
755 return [] 759 return []
756 760
757 761
758 def _RietveldOwnerAndApprovers(input_api, email_regexp): 762 def _RietveldOwnerAndApprovers(input_api, email_regexp):
759 """Return the owner and approvers of a change, if any.""" 763 """Return the owner and approvers of a change, if any."""
760 # TODO(dpranke): Should figure out if input_api.host_url is supposed to 764 if not input_api.change.issue:
761 # be a host or a scheme+host and normalize it there. 765 return None, None
762 host = input_api.host_url 766
763 if not host.startswith('http://') and not host.startswith('https://'): 767 issue_props = input_api.rietveld.get_issue_properties(
764 host = 'http://' + host 768 int(input_api.change.issue), True)
765 url = '%s/api/%s?messages=true' % (host, input_api.change.issue)
766 issue_props = input_api.json.load(input_api.urllib2.urlopen(url))
767 owner_email = issue_props['owner_email'] 769 owner_email = issue_props['owner_email']
768 770
769 def match_reviewer(r): 771 def match_reviewer(r):
770 return email_regexp.match(r) and r != owner_email 772 return email_regexp.match(r) and r != owner_email
771 773
772 messages = issue_props.get('messages', []) 774 messages = issue_props.get('messages', [])
773 approvers = set( 775 approvers = set(
774 m['sender'] for m in messages 776 m['sender'] for m in messages
775 if m.get('approval') and match_reviewer(m['sender'])) 777 if m.get('approval') and match_reviewer(m['sender']))
776 778
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
910 results.extend(input_api.canned_checks.CheckChangeSvnEolStyle( 912 results.extend(input_api.canned_checks.CheckChangeSvnEolStyle(
911 input_api, output_api, source_file_filter=text_files)) 913 input_api, output_api, source_file_filter=text_files))
912 snapshot("checking svn mime types") 914 snapshot("checking svn mime types")
913 results.extend(input_api.canned_checks.CheckSvnForCommonMimeTypes( 915 results.extend(input_api.canned_checks.CheckSvnForCommonMimeTypes(
914 input_api, output_api)) 916 input_api, output_api))
915 snapshot("checking license") 917 snapshot("checking license")
916 results.extend(input_api.canned_checks.CheckLicense( 918 results.extend(input_api.canned_checks.CheckLicense(
917 input_api, output_api, license_header, source_file_filter=sources)) 919 input_api, output_api, license_header, source_file_filter=sources))
918 snapshot("done") 920 snapshot("done")
919 return results 921 return results
OLDNEW
« no previous file with comments | « no previous file | rietveld.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698