owners: Support '*' when checking approval status.

Bug: 1166467
Change-Id: Ib6c32b11ca2892841cad477cee61edef38a0ed62
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/2628702
Auto-Submit: Edward Lesmes <ehmaldonado@chromium.org>
Commit-Queue: Gavin Mak <gavinmak@google.com>
Reviewed-by: Gavin Mak <gavinmak@google.com>
changes/02/2628702/2
Edward Lesmes 5 years ago committed by LUCI CQ
parent 428143ee24
commit 071c3b1b31

@ -49,6 +49,15 @@ class OwnersClient(object):
All code should use this class to interact with OWNERS files instead of the All code should use this class to interact with OWNERS files instead of the
owners database in owners.py owners database in owners.py
""" """
# '*' means that everyone can approve.
EVERYONE = '*'
# Possible status of a file.
# - INSUFFICIENT_REVIEWERS: The path needs owners approval, but none of its
# owners is currently a reviewer of the change.
# - PENDING: An owner of this path has been added as reviewer, but approval
# has not been given yet.
# - APPROVED: The path has been approved by an owner.
APPROVED = 'APPROVED' APPROVED = 'APPROVED'
PENDING = 'PENDING' PENDING = 'PENDING'
INSUFFICIENT_REVIEWERS = 'INSUFFICIENT_REVIEWERS' INSUFFICIENT_REVIEWERS = 'INSUFFICIENT_REVIEWERS'
@ -78,7 +87,11 @@ class OwnersClient(object):
See GetChangeApprovalStatus for description of the returned value. See GetChangeApprovalStatus for description of the returned value.
""" """
approvers = set(approvers) approvers = set(approvers)
if approvers:
approvers.add(self.EVERYONE)
reviewers = set(reviewers) reviewers = set(reviewers)
if reviewers:
reviewers.add(self.EVERYONE)
status = {} status = {}
owners_by_path = self.BatchListOwners(paths) owners_by_path = self.BatchListOwners(paths)
for path, owners in owners_by_path.items(): for path, owners in owners_by_path.items():
@ -176,7 +189,7 @@ class GerritClient(OwnersClient):
def ListOwners(self, path): def ListOwners(self, path):
# GetOwnersForFile returns a list of account details sorted by order of # GetOwnersForFile returns a list of account details sorted by order of
# best reviewer for path. If code owners have the same score, the order is # best reviewer for path. If owners have the same score, the order is
# random. # random.
data = gerrit_util.GetOwnersForFile( data = gerrit_util.GetOwnersForFile(
self._host, self._project, self._branch, path) self._host, self._project, self._branch, path)

@ -106,17 +106,28 @@ class OwnersClientTest(unittest.TestCase):
'approved': ['approver@example.com'], 'approved': ['approver@example.com'],
'pending': ['reviewer@example.com'], 'pending': ['reviewer@example.com'],
'insufficient': ['insufficient@example.com'], 'insufficient': ['insufficient@example.com'],
'everyone': [owners_client.OwnersClient.EVERYONE],
} }
status = self.client.GetFilesApprovalStatus(
['approved', 'pending', 'insufficient'],
['approver@example.com'], ['reviewer@example.com'])
self.assertEqual( self.assertEqual(
status, self.client.GetFilesApprovalStatus(
['approved', 'pending', 'insufficient'],
['approver@example.com'], ['reviewer@example.com']),
{ {
'approved': owners_client.OwnersClient.APPROVED, 'approved': owners_client.OwnersClient.APPROVED,
'pending': owners_client.OwnersClient.PENDING, 'pending': owners_client.OwnersClient.PENDING,
'insufficient': owners_client.OwnersClient.INSUFFICIENT_REVIEWERS, 'insufficient': owners_client.OwnersClient.INSUFFICIENT_REVIEWERS,
}) })
self.assertEqual(
self.client.GetFilesApprovalStatus(
['everyone'], ['anyone@example.com'], []),
{'everyone': owners_client.OwnersClient.APPROVED})
self.assertEqual(
self.client.GetFilesApprovalStatus(
['everyone'], [], ['anyone@example.com']),
{'everyone': owners_client.OwnersClient.PENDING})
self.assertEqual(
self.client.GetFilesApprovalStatus(['everyone'], [], []),
{'everyone': owners_client.OwnersClient.INSUFFICIENT_REVIEWERS})
def test_owner_combinations(self): def test_owner_combinations(self):
owners = [alice, bob, chris, dave, emily] owners = [alice, bob, chris, dave, emily]

Loading…
Cancel
Save