Select a minimal number of owners for a set of files

This CL adds a function which takes a set of files, and attempts to
select a single owner for all of them. If it cannot, it falls back to
the standard owner selection algorithm, which may result in more owners
being chosen than necessary, but guarantees that a valid set of owners
is always returned.

Bug: 389069356
Change-Id: I985804040f149a02bfb5b3c6b946602a81334e7c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6321289
Reviewed-by: Josip Sokcevic <sokcevic@chromium.org>
Commit-Queue: Devon Loehr <dloehr@google.com>
This commit is contained in:
Devon Loehr
2025-03-04 12:19:30 -08:00
committed by LUCI CQ
parent 20193073f8
commit c48f866fcf
2 changed files with 62 additions and 0 deletions

View File

@@ -244,6 +244,33 @@ class OwnersClientTest(unittest.TestCase):
self.client.BatchListOwners(
['bar/everyone/foo.txt', 'bar/everyone/bar.txt', 'bar/foo/']))
def testSuggestMinimalOwners(self):
self.client.owners_by_path = {
'bar/everyone/foo.txt': [alice, bob, emily],
'bar/everyone/bar.txt': [bob, emily],
'bar/foo/': [bob, chris, emily],
'baz/baz/baz': [chris, dave, emily]
}
self.assertEqual([bob],
self.client.SuggestMinimalOwners([
'bar/everyone/foo.txt', 'bar/everyone/bar.txt',
'bar/foo/'
]))
self.assertEqual([chris],
self.client.SuggestMinimalOwners(
['bar/foo/', 'baz/baz/baz']))
# If no common owner exists, fallback to returning multiple owners
self.assertEqual([alice, bob, chris],
self.client.SuggestMinimalOwners([
'bar/everyone/foo.txt', 'bar/everyone/bar.txt',
'bar/foo/', 'baz/baz/baz'
],
exclude=[emily]))
class GetCodeOwnersClientTest(unittest.TestCase):
def setUp(self):