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 630 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
641 approvers = _Approvers(input_api, owners_db.email_regexp) | 641 approvers = _Approvers(input_api, owners_db.email_regexp) |
642 missing_files = owners_db.files_not_covered_by(affected_files, approvers) | 642 missing_files = owners_db.files_not_covered_by(affected_files, approvers) |
643 if missing_files: | 643 if missing_files: |
644 return [output_api.PresubmitError('Missing LGTM from an OWNER for: %s' % | 644 return [output_api.PresubmitError('Missing LGTM from an OWNER for: %s' % |
645 ','.join(missing_files))] | 645 ','.join(missing_files))] |
646 return [] | 646 return [] |
647 elif input_api.change.tags.get('R'): | 647 elif input_api.change.tags.get('R'): |
648 return [] | 648 return [] |
649 | 649 |
650 suggested_reviewers = owners_db.reviewers_for(affected_files) | 650 suggested_reviewers = owners_db.reviewers_for(affected_files) |
651 return [output_api.PresubmitAddText('R=%s' % ','.join(suggested_reviewers))] | 651 return [output_api.PresubmitAddReviewers(suggested_reviewers)] |
652 | 652 |
653 | 653 |
654 def _Approvers(input_api, email_regexp): | 654 def _Approvers(input_api, email_regexp): |
655 if not input_api.change.issue: | 655 if not input_api.change.issue: |
656 return [] | 656 return [] |
657 | 657 |
658 path = '/api/%s?messages=true' | 658 path = '/api/%s?messages=true' |
659 url = (input_api.host_url + path) % input_api.change.issue | 659 url = (input_api.host_url + path) % input_api.change.issue |
660 | 660 |
661 f = input_api.urllib2.urlopen(url) | 661 f = input_api.urllib2.urlopen(url) |
662 issue_props = input_api.json.load(f) | 662 issue_props = input_api.json.load(f) |
663 owner = input_api.re.escape(issue_props['owner']) | 663 owner = input_api.re.escape(issue_props['owner']) |
664 | 664 |
665 # TODO(dpranke): This mimics the logic in | 665 # TODO(dpranke): This mimics the logic in |
666 # /tools/commit-queue/verifiers/reviewer_lgtm.py | 666 # /tools/commit-queue/verifiers/reviewer_lgtm.py |
667 # We should share the code and/or remove the check there where it is | 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). | 668 # redundant (since the commit queue also enforces the presubmit checks). |
669 def match_reviewer(r): | 669 def match_reviewer(r): |
670 return email_regexp.match(r) and not input_api.re.match(owner, r) | 670 return email_regexp.match(r) and not input_api.re.match(owner, r) |
671 | 671 |
672 approvers = [] | 672 approvers = [] |
673 for m in issue_props.get('messages', []): | 673 for m in issue_props.get('messages', []): |
674 if 'lgtm' in m['text'].lower() and match_reviewer(m['sender']): | 674 if 'lgtm' in m['text'].lower() and match_reviewer(m['sender']): |
675 approvers.append(m['sender']) | 675 approvers.append(m['sender']) |
676 return set(approvers) | 676 return set(approvers) |
677 | 677 |
OLD | NEW |