Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(228)

Unified Diff: presubmit_canned_checks.py

Issue 1927773002: Reland Implement owners check in presubmit for Gerrit. (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@P300
Patch Set: gerrit fix Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « git_cl.py ('k') | presubmit_support.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: presubmit_canned_checks.py
diff --git a/presubmit_canned_checks.py b/presubmit_canned_checks.py
index e21d08675f27849a0a40a1a580908a36b2826d3e..1e16d8fffba2a70c69c75de569b37e9b8d0edbd7 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,26 @@ 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.change.issue:
+ if input_api.gerrit:
+ res = _GerritOwnerAndReviewers(input_api, email_regexp, approval_needed)
+ else:
+ # Rietveld is default.
+ res = _RietveldOwnerAndReviewers(input_api, email_regexp, approval_needed)
+ if res:
+ return res
+
+ reviewers = set()
+ if not approval_needed:
+ reviewers = _ReviewersFromChange(input_api.change)
+ return None, reviewers
+
def _GetRietveldIssueProps(input_api, messages):
"""Gets the issue properties from rietveld."""
@@ -926,35 +945,51 @@ 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.
If approval_needed is True, only reviewers who have approved the change
will be returned.
+ Returns None if can't fetch issue properties from codereview.
"""
issue_props = _GetRietveldIssueProps(input_api, True)
if not issue_props:
- reviewers = set()
- if not approval_needed:
- reviewers = _ReviewersFromChange(input_api.change)
- return None, reviewers
+ return None
if not approval_needed:
return issue_props['owner_email'], set(issue_props['reviewers'])
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.
+ Returns None if can't fetch issue properties from codereview.
+ """
+ issue = input_api.change.issue
+ if not issue:
+ return None
+
+ 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(
« no previous file with comments | « git_cl.py ('k') | presubmit_support.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698