Chromium Code Reviews| Index: presubmit_canned_checks.py |
| diff --git a/presubmit_canned_checks.py b/presubmit_canned_checks.py |
| index e21d08675f27849a0a40a1a580908a36b2826d3e..0d70aa32365cbf94c8b167f848e92c887e4ad73e 100644 |
| --- a/presubmit_canned_checks.py |
| +++ b/presubmit_canned_checks.py |
| @@ -875,8 +875,7 @@ def CheckOwners(input_api, output_api, source_file_filter=None): |
| input_api.change.AffectedFiles(file_filter=source_file_filter)]) |
| owners_db = input_api.owners_db |
| - # TODO(tandrii): this will always return None, set() in case of Gerrit. |
| - owner_email, reviewers = _RietveldOwnerAndReviewers( |
| + owner_email, reviewers = _CodereviewOwnersAndReviewers( |
| input_api, |
| owners_db.email_regexp, |
| approval_needed=input_api.is_committing) |
| @@ -905,6 +904,18 @@ def CheckOwners(input_api, output_api, source_file_filter=None): |
| return [output('Missing LGTM from someone other than %s' % owner_email)] |
| return [] |
| +def _CodereviewOwnersAndReviewers(input_api, email_regexp, approval_needed): |
| + """Return the owner and reviewers of a change, if any. |
| + |
| + If approval_needed is True, only reviewers who have approved the change |
| + will be returned. |
| + """ |
| + if input_api.gerrit: |
| + return _GerritOwnerAndReviewers(input_api, email_regexp, approval_needed) |
| + else: |
| + # Rietveld is default. |
| + return _RietveldOwnerAndReviewers(input_api, email_regexp, approval_needed) |
| + |
| def _GetRietveldIssueProps(input_api, messages): |
| """Gets the issue properties from rietveld.""" |
| @@ -926,6 +937,9 @@ def _ReviewersFromChange(change): |
| return set(reviewer for reviewer in reviewers if '@' in reviewer) |
| +def _match_reviewer_email(r, owner_email, email_regexp): |
| + return email_regexp.match(r) and r != owner_email |
| + |
| def _RietveldOwnerAndReviewers(input_api, email_regexp, approval_needed=False): |
| """Return the owner and reviewers of a change, if any. |
| @@ -944,17 +958,34 @@ def _RietveldOwnerAndReviewers(input_api, email_regexp, approval_needed=False): |
| owner_email = issue_props['owner_email'] |
| - def match_reviewer(r): |
| - return email_regexp.match(r) and r != owner_email |
| - |
| messages = issue_props.get('messages', []) |
| approvers = set( |
| m['sender'] for m in messages |
| - if m.get('approval') and match_reviewer(m['sender'])) |
| - |
| + if m.get('approval') and _match_reviewer_email(m['sender'], owner_email, |
| + email_regexp)) |
| return owner_email, approvers |
| +def _GerritOwnerAndReviewers(input_api, email_regexp, approval_needed=False): |
| + """Return the owner and reviewers of a change, if any. |
| + |
| + If approval_needed is True, only reviewers who have approved the change |
| + will be returned. |
| + """ |
| + issue = input_api.change.issue |
|
Michael Achenbach
2016/04/28 07:17:29
5 lines code dupe. Maybe you can make this common?
tandrii(chromium)
2016/04/28 19:31:50
yep, tricky part is backwards compat, but I think
Michael Achenbach
2016/04/29 08:10:18
Ok - I just meant to share the duplicated code in
Michael Achenbach
2016/05/06 15:01:42
Guess this caused https://bugs.chromium.org/p/chro
|
| + if not issue: |
| + reviewers = set() |
| + if not approval_needed: |
| + reviewers = _ReviewersFromChange(input_api.change) |
| + return None, reviewers |
| + |
| + owner_email = input_api.gerrit.GetChangeOwner(issue) |
| + reviewers = set( |
| + r for r in input_api.gerrit.GetChangeReviewers(issue, approval_needed) |
| + if _match_reviewer_email(r, owner_email, email_regexp)) |
| + return owner_email, reviewers |
| + |
| + |
| def _CheckConstNSObject(input_api, output_api, source_file_filter): |
| """Checks to make sure no objective-c files have |const NSSomeClass*|.""" |
| pattern = input_api.re.compile( |