diff --git a/owners_client.py b/owners_client.py index d40d799fa..2fba02496 100644 --- a/owners_client.py +++ b/owners_client.py @@ -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) diff --git a/tests/owners_client_test.py b/tests/owners_client_test.py index 55d6fdd20..1ecbe9c53 100644 --- a/tests/owners_client_test.py +++ b/tests/owners_client_test.py @@ -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]