| 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, 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) |
| 633 | 636 |
| 634 if input_api.is_committing and input_api.tbr: | 637 if input_api.is_committing and input_api.tbr: |
| 635 return [output_api.PresubmitNotifyResult( | 638 return [output_api.PresubmitNotifyResult( |
| 636 '--tbr was specified, skipping OWNERS check')] | 639 '--tbr was specified, skipping OWNERS check')] |
| 637 elif input_api.is_committing: | 640 elif input_api.is_committing: |
| 638 approvers = _Approvers(input_api, owners_db.email_regexp) | 641 approvers = _Approvers(input_api, owners_db.email_regexp) |
| 639 missing_files = owners_db.files_not_covered_by(affected_files, approvers) | 642 missing_files = owners_db.files_not_covered_by(affected_files, approvers) |
| 640 if missing_files: | 643 if missing_files: |
| 641 return [output_api.PresubmitError('Missing LGTM from an OWNER for: %s' % | 644 return [output_api.PresubmitError('Missing LGTM from an OWNER for: %s' % |
| 642 ','.join(missing_files))] | 645 ','.join(missing_files))] |
| (...skipping 22 matching lines...) Expand all Loading... |
| 665 # redundant (since the commit queue also enforces the presubmit checks). | 668 # redundant (since the commit queue also enforces the presubmit checks). |
| 666 def match_reviewer(r): | 669 def match_reviewer(r): |
| 667 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) |
| 668 | 671 |
| 669 approvers = [] | 672 approvers = [] |
| 670 for m in issue_props['messages']: | 673 for m in issue_props['messages']: |
| 671 if 'lgtm' in m['text'].lower() and match_reviewer(m['sender']): | 674 if 'lgtm' in m['text'].lower() and match_reviewer(m['sender']): |
| 672 approvers.append(m['sender']) | 675 approvers.append(m['sender']) |
| 673 return set(approvers) | 676 return set(approvers) |
| 674 | 677 |
| OLD | NEW |