[owners] Refactor OwnersClient.
- Remove GetChangeApprovalStatus and GetFilesApprovalStatus.
- Make host, project and branch part of GerritClient.
- Rename ListOwnersForFile to ListOwners.
Change-Id: I1f610a64f0217ce54e5ce4a210026535adc1c2e5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/2587268
Commit-Queue: Edward Lesmes <ehmaldonado@chromium.org>
Reviewed-by: Gavin Mak <gavinmak@google.com>
diff --git a/git_cl.py b/git_cl.py
index 5f9dba5..c6fdd98 100755
--- a/git_cl.py
+++ b/git_cl.py
@@ -42,7 +42,6 @@
import git_new_branch
import metrics
import metrics_utils
-import owners
import owners_client
import owners_finder
import presubmit_canned_checks
@@ -1376,14 +1375,11 @@
add_owners = []
if options.add_owners_to:
# Fill gaps in OWNERS coverage to tbrs/reviewers if requested.
- project = self.GetGerritProject()
- branch = self.GetCommonAncestorWithUpstream()
client = owners_client.DepotToolsClient(
- host=self.GetGerritHost(),
root=settings.GetRoot(),
- branch=branch)
+ branch=self.GetCommonAncestorWithUpstream())
status = client.GetFilesApprovalStatus(
- project, branch, files, [], options.tbrs + options.reviewers)
+ files, [], options.tbrs + options.reviewers)
missing_files = [
f for f in files
if status[f] == owners_client.INSUFFICIENT_REVIEWERS
@@ -4789,16 +4785,13 @@
if len(args) == 0:
print('No files specified for --show-all. Nothing to do.')
return 0
- project = cl.GetGerritProject()
- branch = cl.GetCommonAncestorWithUpstream()
client = owners_client.DepotToolsClient(
- host=cl.GetGerritHost(),
root=settings.GetRoot(),
- branch=branch)
- for arg in args:
- print('Owners for %s:' % arg)
- for owner in client.ListOwnersForFile(project, branch, arg):
- print(' - %s' % owner)
+ branch=cl.GetCommonAncestorWithUpstream())
+ owners_by_file = client.BatchListOwners(args)
+ for f, owners in owners_by_file.items():
+ print('Owners for %s:' % f)
+ print('\n'.join(' - %s' % owner for owner in owners))
return 0
if args:
@@ -4813,13 +4806,10 @@
affected_files = cl.GetAffectedFiles(base_branch)
if options.batch:
- project = cl.GetGerritProject()
- branch = cl.GetCommonAncestorWithUpstream()
client = owners_client.DepotToolsClient(
- host=cl.GetGerritHost(),
root=settings.GetRoot(),
- branch=branch)
- print('\n'.join(client.SuggestOwners(project, branch, affected_files)))
+ branch=cl.GetCommonAncestorWithUpstream())
+ print('\n'.join(client.SuggestOwners(affected_files)))
return 0
owner_files = [f for f in affected_files if 'OWNERS' in os.path.basename(f)]