Commit 1076f389 authored by Edward Lesmes's avatar Edward Lesmes Committed by LUCI CQ

Reland "presubmit: Use new API to check for owners approval"

This is a reland of 0489cc12

Don't remove email_regexp argument, as downstream still passes it.

Original change's description:
> Reland "presubmit: Use new API to check for owners approval"
>
> New API was updated to properly support '*' as owner.
>
> Change-Id: If14144f83484731fd5534c03cb9fde4b18f49fe9
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/2628703
> Auto-Submit: Edward Lesmes <ehmaldonado@chromium.org>
> Reviewed-by: Josip Sokcevic <sokcevic@google.com>
> Commit-Queue: Edward Lesmes <ehmaldonado@chromium.org>

Change-Id: Id137aca0036c2ebf11ec56a12f4e053cd2cc6637
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/2639411
Auto-Submit: Edward Lesmes <ehmaldonado@chromium.org>
Commit-Queue: Gavin Mak <gavinmak@google.com>
Reviewed-by: 's avatarGavin Mak <gavinmak@google.com>
parent d36dbbd7
......@@ -1167,17 +1167,16 @@ def CheckOwners(
affected_files = set([f.LocalPath() for f in
input_api.change.AffectedFiles(file_filter=source_file_filter)])
owners_db = input_api.owners_db
owners_db.override_files = input_api.change.OriginalOwnersFiles()
owner_email, reviewers = GetCodereviewOwnerAndReviewers(
input_api,
owners_db.email_regexp,
approval_needed=input_api.is_committing)
input_api, None, approval_needed=input_api.is_committing)
owner_email = owner_email or input_api.change.author_email
missing_files = owners_db.files_not_covered_by(
affected_files, reviewers.union([owner_email]))
approval_status = input_api.owners_client.GetFilesApprovalStatus(
affected_files, reviewers.union([owner_email]), [])
missing_files = [
f for f in affected_files
if approval_status[f] != input_api.owners_client.APPROVED]
affects_owners = any('OWNERS' in name for name in missing_files)
if input_api.is_committing:
......@@ -1206,7 +1205,7 @@ def CheckOwners(
if tbr and affects_owners:
output_list.append(output_fn('TBR for OWNERS files are ignored.'))
if not input_api.is_committing:
suggested_owners = owners_db.reviewers_for(missing_files, owner_email)
suggested_owners = input_api.owners_client.SuggestOwners(missing_files)
output_list.append(output_fn('Suggested OWNERS: ' +
'(Use "git-cl owners" to interactively select owners.)\n %s' %
('\n '.join(suggested_owners))))
......@@ -1217,12 +1216,14 @@ def CheckOwners(
return []
def GetCodereviewOwnerAndReviewers(input_api, email_regexp, approval_needed):
def GetCodereviewOwnerAndReviewers(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.
"""
# Recognizes 'X@Y' email addresses. Very simplistic.
EMAIL_REGEXP = input_api.re.compile(r'^[\w\-\+\%\.]+\@[\w\-\+\%\.]+$')
issue = input_api.change.issue
if not issue:
return None, (set() if approval_needed else
......@@ -1231,7 +1232,7 @@ def GetCodereviewOwnerAndReviewers(input_api, email_regexp, approval_needed):
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))
if _match_reviewer_email(r, owner_email, EMAIL_REGEXP))
input_api.logging.debug('owner: %s; approvals given by: %s',
owner_email, ', '.join(sorted(reviewers)))
return owner_email, reviewers
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment