Commit 99399cae authored by Gavin Mak's avatar Gavin Mak Committed by LUCI CQ

[owners] Add BatchListOwners

BatchListOwners uses git_common's ScopedPool method to run
ListOwnersForFile in parallel for multiple paths.

Change-Id: I545072e16181407665c8b009f87fccfb7355d7d8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/2585657Reviewed-by: 's avatarEdward Lesmes <ehmaldonado@chromium.org>
Commit-Queue: Gavin Mak <gavinmak@google.com>
parent c94b21d6
......@@ -7,6 +7,7 @@ import os
import random
import gerrit_util
import git_common
import owners as owners_db
import scm
......@@ -66,6 +67,12 @@ class OwnersClient(object):
"""
raise Exception('Not implemented')
def BatchListOwners(self, project, branch, paths):
"""Returns a dictionary {path: [owners]}."""
with git_common.ScopedPool(kind='threads') as pool:
return dict(pool.imap_unordered(
lambda p: (p, self.ListOwnersForFile(project, branch, p)), paths))
def GetChangeApprovalStatus(self, change_id):
"""Check the approval status for the latest revision_id in a change.
......
......@@ -256,6 +256,23 @@ class OwnersClientTest(unittest.TestCase):
['abc', 'acb', 'bac', 'bca', 'cab', 'cba']),
(chris, bob))
def testBatchListOwners(self):
self.client.owners_by_path = {
'bar/everyone/foo.txt': [alice, bob],
'bar/everyone/bar.txt': [bob],
'bar/foo/': [bob, chris]
}
self.assertEquals(
{
'bar/everyone/foo.txt': [alice, bob],
'bar/everyone/bar.txt': [bob],
'bar/foo/': [bob, chris]
},
self.client.BatchListOwners(
'project', 'branch',
['bar/everyone/foo.txt', 'bar/everyone/bar.txt', 'bar/foo/']))
if __name__ == '__main__':
unittest.main()
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