From b4f4226d153e993888f6e7429dcc9aca480e680e Mon Sep 17 00:00:00 2001 From: Edward Lesmes Date: Tue, 10 Nov 2020 23:41:35 +0000 Subject: [PATCH] [owners] Implement ListOwnersForFile for Depot Tools Add DepotToolsClient to implement the OwnersClient API for Depot Tools, and implement the ListOwnersForFile method. Change-Id: I933a262898439d879c919d695aa62d7702b4c9a4 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/2530509 Auto-Submit: Edward Lesmes Reviewed-by: Anthony Polito Commit-Queue: Edward Lesmes --- owners_client.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/owners_client.py b/owners_client.py index e252ac18a..b5acc86ae 100644 --- a/owners_client.py +++ b/owners_client.py @@ -2,6 +2,8 @@ # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. +import owners + class OwnersClient(object): """Interact with OWNERS files in a repository. @@ -24,10 +26,21 @@ class OwnersClient(object): """List all owners for a file.""" raise Exception('Not implemented') - def IsChangeApproved(self, change_number): + def IsChangeApproved(self, change_id): """Check if the latest patch set for a change has been approved.""" raise Exception('Not implemented') - def IsOwnerConfigurationValid(self, change_number, patch): + def IsOwnerConfigurationValid(self, change_id, patch): """Check if the owners configuration in a change is valid.""" raise Exception('Not implemented') + + +class DepotToolsClient(OwnersClient): + """Implement OwnersClient using owners.py Database.""" + def __init__(self, host, root): + super(DepotToolsClient, self).__init__(host) + self._root = root + self._db = owners.Database(root, open, os.path) + + def ListOwnersForFile(self, _project, _branch, path): + return sorted(self._db.all_possible_owners([arg], None))