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 608 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, host_url, email_regexp, |
| 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 email_regexp = input_api.re.compile(email_regexp) | |
| 635 owners_db.email_regexp = email_regexp | |
| 633 | 636 |
| 634 if input_api.is_committing: | 637 if input_api.is_committing: |
| 638 approvers = _Approvers(input_api, host_url, email_regexp) | |
| 635 missing_files = owners_db.files_not_covered_by(affected_files, | 639 missing_files = owners_db.files_not_covered_by(affected_files, |
| 636 input_api.change.approvers) | 640 approvers) |
| 637 if missing_files: | 641 if missing_files: |
| 638 return [output_api.PresubmitError('Missing owner LGTM for: %s' % | 642 return [output_api.PresubmitError('Missing LGTM from an OWNER for: %s' % |
| 639 ','.join(missing_files))] | 643 ','.join(missing_files))] |
| 640 return [] | 644 return [] |
| 641 elif input_api.change.tags.get('R'): | 645 elif input_api.change.tags.get('R'): |
| 642 return [] | 646 return [] |
| 643 | 647 |
| 644 suggested_reviewers = owners_db.reviewers_for(affected_files) | 648 suggested_reviewers = owners_db.reviewers_for(affected_files) |
| 645 return [output_api.PresubmitAddText('R=%s' % ','.join(suggested_reviewers))] | 649 return [output_api.PresubmitAddText('R=%s' % ','.join(suggested_reviewers))] |
| 650 | |
| 651 | |
| 652 def _Approvers(input_api, host_url, email_regexp): | |
|
M-A Ruel
2011/03/10 13:37:54
I don't think we want this there. This means that
| |
| 653 if not input_api.change.issue: | |
| 654 return [] | |
| 655 | |
| 656 path = '/api/%s?messages=true' | |
| 657 url = (host_url + path) % input_api.change.issue | |
| 658 | |
| 659 f = input_api.urllib2.urlopen(url) | |
| 660 issue_props = input_api.json.load(f) | |
| 661 owner = input_api.re.escape(issue_props['owner']) | |
| 662 | |
| 663 # TODO(dpranke): This mimics the logic in | |
| 664 # /tools/commit-queue/verifiers/reviewer_lgtm.py | |
| 665 # We should share the code and/or remove the check there where it is | |
| 666 # redundant (since the commit queue also enforces the presubmit checks). | |
| 667 def match_reviewer(r): | |
| 668 return email_regexp.match(r) and not input_api.re.match(owner, r) | |
| 669 | |
| 670 approvers = [] | |
| 671 for m in issue_props['messages']: | |
| 672 if 'lgtm' in m['text'].lower() and match_reviewer(m['sender']): | |
| 673 approvers.append(m['sender']) | |
| 674 return set(approvers) | |
| 675 | |
| OLD | NEW |