OLD | NEW |
---|---|
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 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 import os as _os | 7 import os as _os |
8 _HERE = _os.path.dirname(_os.path.abspath(__file__)) | 8 _HERE = _os.path.dirname(_os.path.abspath(__file__)) |
9 | 9 |
10 | 10 |
(...skipping 834 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
845 | 845 |
846 | 846 |
847 def _GetRietveldIssueProps(input_api, messages): | 847 def _GetRietveldIssueProps(input_api, messages): |
848 """Gets the issue properties from rietveld.""" | 848 """Gets the issue properties from rietveld.""" |
849 issue = input_api.change.issue | 849 issue = input_api.change.issue |
850 if issue and input_api.rietveld: | 850 if issue and input_api.rietveld: |
851 return input_api.rietveld.get_issue_properties( | 851 return input_api.rietveld.get_issue_properties( |
852 issue=int(issue), messages=messages) | 852 issue=int(issue), messages=messages) |
853 | 853 |
854 | 854 |
855 def _ReviewersFromChange(change): | |
856 """Return the reviewers specified in the |change|, if any.""" | |
857 reviewers = set() | |
858 if change.R: | |
859 reviewers.update(set([r.strip() for r in change.R.split(',')])) | |
860 if change.TBR: | |
861 reviewers.update(set([r.strip() for r in change.TBR.split(',')])) | |
862 return reviewers | |
863 | |
864 | |
855 def _RietveldOwnerAndReviewers(input_api, email_regexp, approval_needed=False): | 865 def _RietveldOwnerAndReviewers(input_api, email_regexp, approval_needed=False): |
856 """Return the owner and reviewers of a change, if any. | 866 """Return the owner and reviewers of a change, if any. |
857 | 867 |
858 If approval_needed is True, only reviewers who have approved the change | 868 If approval_needed is True, only reviewers who have approved the change |
859 will be returned. | 869 will be returned. |
860 """ | 870 """ |
861 issue_props = _GetRietveldIssueProps(input_api, True) | 871 issue_props = _GetRietveldIssueProps(input_api, True) |
862 if not issue_props: | 872 if not issue_props: |
863 return None, set() | 873 return None, _ReviewersFromChange(input_api.change) |
agable
2014/03/14 15:11:03
This doesn't coincide with the docstring, which sa
Ilya Sherman
2014/03/18 01:18:35
Good catch. Fixed.
| |
864 | 874 |
865 if not approval_needed: | 875 if not approval_needed: |
866 return issue_props['owner_email'], set(issue_props['reviewers']) | 876 return issue_props['owner_email'], set(issue_props['reviewers']) |
867 | 877 |
868 owner_email = issue_props['owner_email'] | 878 owner_email = issue_props['owner_email'] |
869 | 879 |
870 def match_reviewer(r): | 880 def match_reviewer(r): |
871 return email_regexp.match(r) and r != owner_email | 881 return email_regexp.match(r) and r != owner_email |
872 | 882 |
873 messages = issue_props.get('messages', []) | 883 messages = issue_props.get('messages', []) |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1046 def CheckPatchFormatted(input_api, output_api): | 1056 def CheckPatchFormatted(input_api, output_api): |
1047 import git_cl | 1057 import git_cl |
1048 cmd = ['cl', 'format', '--dry-run', input_api.PresubmitLocalPath()] | 1058 cmd = ['cl', 'format', '--dry-run', input_api.PresubmitLocalPath()] |
1049 code, _ = git_cl.RunGitWithCode(cmd, suppress_stderr=True) | 1059 code, _ = git_cl.RunGitWithCode(cmd, suppress_stderr=True) |
1050 if code == 2: | 1060 if code == 2: |
1051 return [output_api.PresubmitPromptWarning( | 1061 return [output_api.PresubmitPromptWarning( |
1052 'Your patch is not formatted, please run git cl format.')] | 1062 'Your patch is not formatted, please run git cl format.')] |
1053 # As this is just a warning, ignore all other errors if the user | 1063 # As this is just a warning, ignore all other errors if the user |
1054 # happens to have a broken clang-format, doesn't use git, etc etc. | 1064 # happens to have a broken clang-format, doesn't use git, etc etc. |
1055 return [] | 1065 return [] |
OLD | NEW |