Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 619 out.append('%s has %d build(s) pending' % | 619 out.append('%s has %d build(s) pending' % |
| 620 (builder_name, pending_builds_len)) | 620 (builder_name, pending_builds_len)) |
| 621 if out: | 621 if out: |
| 622 return [output_api.PresubmitPromptWarning( | 622 return [output_api.PresubmitPromptWarning( |
| 623 'Build(s) pending. It is suggested to wait that no more than %d ' | 623 'Build(s) pending. It is suggested to wait that no more than %d ' |
| 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, email_regexp=None, |
| 630 source_file_filter=None): | |
| 630 affected_files = set([f.LocalPath() for f in | 631 affected_files = set([f.LocalPath() for f in |
| 631 input_api.change.AffectedFiles(source_file_filter)]) | 632 input_api.change.AffectedFiles(source_file_filter)]) |
| 632 owners_db = input_api.owners_db | 633 owners_db = input_api.owners_db |
| 634 if email_regexp: | |
| 635 owners_db.email_regexp = input_api.re.compile(email_regexp) | |
|
M-A Ruel
2011/03/11 21:19:09
If there is:
a/PRESUBMIT.py
a/b/PRESUBMIT.py
both
| |
| 633 | 636 |
| 634 if input_api.is_committing: | 637 if input_api.is_committing and input_api.is_tbr: |
| 635 missing_files = owners_db.files_not_covered_by(affected_files, | 638 return [output_api.PresubmitNotifyResult( |
| 636 input_api.change.approvers) | 639 '--tbr was specified, skipping OWNERS check')] |
| 640 elif input_api.is_committing: | |
| 641 approvers = _Approvers(input_api, owners_db.email_regexp) | |
| 642 missing_files = owners_db.files_not_covered_by(affected_files, approvers) | |
| 637 if missing_files: | 643 if missing_files: |
| 638 return [output_api.PresubmitError('Missing owner LGTM for: %s' % | 644 return [output_api.PresubmitError('Missing LGTM from an OWNER for: %s' % |
| 639 ','.join(missing_files))] | 645 ','.join(missing_files))] |
| 640 return [] | 646 return [] |
| 641 elif input_api.change.tags.get('R'): | 647 elif input_api.change.tags.get('R'): |
| 642 return [] | 648 return [] |
| 643 | 649 |
| 644 suggested_reviewers = owners_db.reviewers_for(affected_files) | 650 suggested_reviewers = owners_db.reviewers_for(affected_files) |
| 645 return [output_api.PresubmitAddText('R=%s' % ','.join(suggested_reviewers))] | 651 return [output_api.PresubmitAddText('R=%s' % ','.join(suggested_reviewers))] |
| 652 | |
| 653 | |
| 654 def _Approvers(input_api, email_regexp): | |
| 655 if not input_api.change.issue: | |
| 656 return [] | |
| 657 | |
| 658 path = '/api/%s?messages=true' | |
| 659 url = (input_api.host_url + path) % input_api.change.issue | |
| 660 | |
| 661 f = input_api.urllib2.urlopen(url) | |
| 662 issue_props = input_api.json.load(f) | |
| 663 owner = input_api.re.escape(issue_props['owner']) | |
| 664 | |
| 665 # TODO(dpranke): This mimics the logic in | |
| 666 # /tools/commit-queue/verifiers/reviewer_lgtm.py | |
| 667 # We should share the code and/or remove the check there where it is | |
| 668 # redundant (since the commit queue also enforces the presubmit checks). | |
| 669 def match_reviewer(r): | |
| 670 return email_regexp.match(r) and not input_api.re.match(owner, r) | |
| 671 | |
| 672 approvers = [] | |
| 673 for m in issue_props['messages']: | |
| 674 if 'lgtm' in m['text'].lower() and match_reviewer(m['sender']): | |
| 675 approvers.append(m['sender']) | |
| 676 return set(approvers) | |
| 677 | |
| OLD | NEW |