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

Side by Side Diff: presubmit_canned_checks.py

Issue 12326151: Add a way to require approval from owners other than the author. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: fix wording in comment Created 7 years, 9 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 | « owners.py ('k') | tests/owners_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 751 matching lines...) Expand 10 before | Expand all | Expand 10 after
762 out.append('%s has %d build(s) pending' % 762 out.append('%s has %d build(s) pending' %
763 (builder_name, pending_builds_len)) 763 (builder_name, pending_builds_len))
764 if out: 764 if out:
765 return [output_api.PresubmitPromptWarning( 765 return [output_api.PresubmitPromptWarning(
766 'Build(s) pending. It is suggested to wait that no more than %d ' 766 'Build(s) pending. It is suggested to wait that no more than %d '
767 'builds are pending.' % max_pendings, 767 'builds are pending.' % max_pendings,
768 long_text='\n'.join(out))] 768 long_text='\n'.join(out))]
769 return [] 769 return []
770 770
771 771
772 def CheckOwners(input_api, output_api, source_file_filter=None): 772 def CheckOwners(input_api, output_api, source_file_filter=None,
773 author_counts_as_owner=True):
773 if input_api.is_committing: 774 if input_api.is_committing:
774 if input_api.tbr: 775 if input_api.tbr:
775 return [output_api.PresubmitNotifyResult( 776 return [output_api.PresubmitNotifyResult(
776 '--tbr was specified, skipping OWNERS check')] 777 '--tbr was specified, skipping OWNERS check')]
777 if not input_api.change.issue: 778 if not input_api.change.issue:
778 return [output_api.PresubmitError("OWNERS check failed: this change has " 779 return [output_api.PresubmitError("OWNERS check failed: this change has "
779 "no Rietveld issue number, so we can't check it for approvals.")] 780 "no Rietveld issue number, so we can't check it for approvals.")]
780 needed = 'LGTM from an OWNER' 781 needed = 'LGTM from an OWNER'
781 output = output_api.PresubmitError 782 output = output_api.PresubmitError
782 else: 783 else:
783 needed = 'OWNER reviewers' 784 needed = 'OWNER reviewers'
784 output = output_api.PresubmitNotifyResult 785 output = output_api.PresubmitNotifyResult
785 786
786 affected_files = set([f.LocalPath() for f in 787 affected_files = set([f.LocalPath() for f in
787 input_api.change.AffectedFiles(file_filter=source_file_filter)]) 788 input_api.change.AffectedFiles(file_filter=source_file_filter)])
788 789
789 owners_db = input_api.owners_db 790 owners_db = input_api.owners_db
790 owner_email, reviewers = _RietveldOwnerAndReviewers( 791 owner_email, reviewers = _RietveldOwnerAndReviewers(
791 input_api, 792 input_api,
792 owners_db.email_regexp, 793 owners_db.email_regexp,
793 approval_needed=input_api.is_committing) 794 approval_needed=input_api.is_committing)
794 795
795 if owner_email: 796 if author_counts_as_owner:
797 if owner_email:
798 message = ''
799 reviewers_plus_owner = reviewers.union(set([owner_email]))
800 else:
801 message = ('\nUntil the issue is uploaded, this list will include '
802 'files for which you are an OWNER.')
803 owner_email = ''
804 reviewers_plus_owner = set()
805 missing_files = owners_db.files_not_covered_by(affected_files,
806 reviewers_plus_owner)
807 else:
796 message = '' 808 message = ''
797 reviewers_plus_owner = reviewers.union(set([owner_email])) 809 missing_files = owners_db.files_not_covered_by(affected_files, reviewers)
798 else:
799 message = ('\nUntil the issue is uploaded, this list will include '
800 'files for which you are an OWNER.')
801 owner_email = ''
802 reviewers_plus_owner = set()
803 810
804 missing_files = owners_db.files_not_covered_by(affected_files,
805 reviewers_plus_owner)
806 if missing_files: 811 if missing_files:
807 output_list = [ 812 output_list = [
808 output('Missing %s for these files:\n %s%s' % 813 output('Missing %s for these files:\n %s%s' %
809 (needed, '\n '.join(missing_files), message))] 814 (needed, '\n '.join(missing_files), message))]
810 if not input_api.is_committing: 815 if not input_api.is_committing:
811 suggested_owners = owners_db.reviewers_for(affected_files) 816 suggested_owners = owners_db.reviewers_for(affected_files, owner_email)
812 output_list.append(output('Suggested OWNERS:\n %s' % 817 output_list.append(output('Suggested OWNERS:\n %s' %
813 ('\n '.join(suggested_owners)))) 818 ('\n '.join(suggested_owners or []))))
814 return output_list 819 return output_list
815 820
816 if input_api.is_committing and not reviewers: 821 if input_api.is_committing and not reviewers:
817 return [output('Missing LGTM from someone other than %s' % owner_email)] 822 return [output('Missing LGTM from someone other than %s' % owner_email)]
818 return [] 823 return []
819 824
820 825
821 def _GetRietveldIssueProps(input_api, messages): 826 def _GetRietveldIssueProps(input_api, messages):
822 """Gets the issue properties from rietveld.""" 827 """Gets the issue properties from rietveld."""
823 issue = input_api.change.issue 828 issue = input_api.change.issue
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
1008 snapshot("checking description") 1013 snapshot("checking description")
1009 results.extend(input_api.canned_checks.CheckChangeHasDescription( 1014 results.extend(input_api.canned_checks.CheckChangeHasDescription(
1010 input_api, output_api)) 1015 input_api, output_api))
1011 results.extend(input_api.canned_checks.CheckDoNotSubmitInDescription( 1016 results.extend(input_api.canned_checks.CheckDoNotSubmitInDescription(
1012 input_api, output_api)) 1017 input_api, output_api))
1013 snapshot("checking do not submit in files") 1018 snapshot("checking do not submit in files")
1014 results.extend(input_api.canned_checks.CheckDoNotSubmitInFiles( 1019 results.extend(input_api.canned_checks.CheckDoNotSubmitInFiles(
1015 input_api, output_api)) 1020 input_api, output_api))
1016 snapshot("done") 1021 snapshot("done")
1017 return results 1022 return results
OLDNEW
« no previous file with comments | « owners.py ('k') | tests/owners_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698