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

Side by Side Diff: presubmit_canned_checks.py

Issue 6657028: Actually check Rietveld for LGTMs in CheckOwners() (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: rename is_tbr to tbr, remove optional email_regexp param from CheckOwners() Created 9 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') | presubmit_support.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 ### Description checks 7 ### Description checks
8 8
9 def CheckChangeHasTestField(input_api, output_api): 9 def CheckChangeHasTestField(input_api, output_api):
10 """Requires that the changelist have a TEST= field.""" 10 """Requires that the changelist have a TEST= field."""
(...skipping 522 matching lines...) Expand 10 before | Expand all | Expand 10 after
533 if result: 533 if result:
534 if input_api.is_committing: 534 if input_api.is_committing:
535 error_type = output_api.PresubmitError 535 error_type = output_api.PresubmitError
536 else: 536 else:
537 error_type = output_api.PresubmitPromptWarning 537 error_type = output_api.PresubmitPromptWarning
538 return [error_type('Fix pylint errors first.')] 538 return [error_type('Fix pylint errors first.')]
539 return [] 539 return []
540 finally: 540 finally:
541 warnings.filterwarnings('default', category=DeprecationWarning) 541 warnings.filterwarnings('default', category=DeprecationWarning)
542 542
543 543 # TODO(dpranke): Get the host_url from the input_api instead
544 def CheckRietveldTryJobExecution(input_api, output_api, host_url, platforms, 544 def CheckRietveldTryJobExecution(input_api, output_api, host_url, platforms,
545 owner): 545 owner):
546 if not input_api.is_committing: 546 if not input_api.is_committing:
547 return [] 547 return []
548 if not input_api.change.issue or not input_api.change.patchset: 548 if not input_api.change.issue or not input_api.change.patchset:
549 return [] 549 return []
550 url = '%s/%d/get_build_results/%d' % ( 550 url = '%s/%d/get_build_results/%d' % (
551 host_url, input_api.change.issue, input_api.change.patchset) 551 host_url, input_api.change.issue, input_api.change.patchset)
552 try: 552 try:
553 connection = input_api.urllib2.urlopen(url) 553 connection = input_api.urllib2.urlopen(url)
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
624 'builds are pending.' % max_pendings, 624 'builds are pending.' % max_pendings,
625 long_text='\n'.join(out))] 625 long_text='\n'.join(out))]
626 return [] 626 return []
627 627
628 628
629 def CheckOwners(input_api, output_api, source_file_filter=None): 629 def CheckOwners(input_api, output_api, source_file_filter=None):
630 affected_files = set([f.LocalPath() for f in 630 affected_files = set([f.LocalPath() for f in
631 input_api.change.AffectedFiles(source_file_filter)]) 631 input_api.change.AffectedFiles(source_file_filter)])
632 owners_db = input_api.owners_db 632 owners_db = input_api.owners_db
633 633
634 if input_api.is_committing: 634 if input_api.is_committing and input_api.tbr:
635 missing_files = owners_db.files_not_covered_by(affected_files, 635 return [output_api.PresubmitNotifyResult(
636 input_api.change.approvers) 636 '--tbr was specified, skipping OWNERS check')]
637 elif input_api.is_committing:
638 approvers = _Approvers(input_api, owners_db.email_regexp)
639 missing_files = owners_db.files_not_covered_by(affected_files, approvers)
637 if missing_files: 640 if missing_files:
638 return [output_api.PresubmitError('Missing owner LGTM for: %s' % 641 return [output_api.PresubmitError('Missing LGTM from an OWNER for: %s' %
639 ','.join(missing_files))] 642 ','.join(missing_files))]
640 return [] 643 return []
641 elif input_api.change.tags.get('R'): 644 elif input_api.change.tags.get('R'):
642 return [] 645 return []
643 646
644 suggested_reviewers = owners_db.reviewers_for(affected_files) 647 suggested_reviewers = owners_db.reviewers_for(affected_files)
645 return [output_api.PresubmitAddText('R=%s' % ','.join(suggested_reviewers))] 648 return [output_api.PresubmitAddText('R=%s' % ','.join(suggested_reviewers))]
649
650
651 def _Approvers(input_api, email_regexp):
652 if not input_api.change.issue:
653 return []
654
655 path = '/api/%s?messages=true'
656 url = (input_api.host_url + path) % input_api.change.issue
657
658 f = input_api.urllib2.urlopen(url)
659 issue_props = input_api.json.load(f)
660 owner = input_api.re.escape(issue_props['owner'])
661
662 # TODO(dpranke): This mimics the logic in
663 # /tools/commit-queue/verifiers/reviewer_lgtm.py
664 # We should share the code and/or remove the check there where it is
665 # redundant (since the commit queue also enforces the presubmit checks).
666 def match_reviewer(r):
667 return email_regexp.match(r) and not input_api.re.match(owner, r)
668
669 approvers = []
670 for m in issue_props['messages']:
671 if 'lgtm' in m['text'].lower() and match_reviewer(m['sender']):
672 approvers.append(m['sender'])
673 return set(approvers)
674
OLDNEW
« no previous file with comments | « owners.py ('k') | presubmit_support.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698