Commit 071c3b1b authored by Edward Lesmes's avatar Edward Lesmes Committed by LUCI CQ

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: 's avatarGavin Mak <gavinmak@google.com>
parent 428143ee
......@@ -49,6 +49,15 @@ class OwnersClient(object):
All code should use this class to interact with OWNERS files instead of the
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'
PENDING = 'PENDING'
INSUFFICIENT_REVIEWERS = 'INSUFFICIENT_REVIEWERS'
......@@ -78,7 +87,11 @@ class OwnersClient(object):
See GetChangeApprovalStatus for description of the returned value.
"""
approvers = set(approvers)
if approvers:
approvers.add(self.EVERYONE)
reviewers = set(reviewers)
if reviewers:
reviewers.add(self.EVERYONE)
status = {}
owners_by_path = self.BatchListOwners(paths)
for path, owners in owners_by_path.items():
......@@ -176,7 +189,7 @@ class GerritClient(OwnersClient):
def ListOwners(self, path):
# 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.
data = gerrit_util.GetOwnersForFile(
self._host, self._project, self._branch, path)
......
......@@ -106,17 +106,28 @@ class OwnersClientTest(unittest.TestCase):
'approved': ['approver@example.com'],
'pending': ['reviewer@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(
status,
self.client.GetFilesApprovalStatus(
['approved', 'pending', 'insufficient'],
['approver@example.com'], ['reviewer@example.com']),
{
'approved': owners_client.OwnersClient.APPROVED,
'pending': owners_client.OwnersClient.PENDING,
'insufficient': owners_client.OwnersClient.INSUFFICIENT_REVIEWERS,
'approved': owners_client.OwnersClient.APPROVED,
'pending': owners_client.OwnersClient.PENDING,
'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):
owners = [alice, bob, chris, dave, emily]
......
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