owners: add owners_rooted_at_file()

This method allows retrieving the owners listed in a file, as well as those
transitively listed in files included by it. This change also adds a new test to
cover this method, which is just a wrapper for the existing
_read_just_the_owners() internal method.

Bug: None
Change-Id: Iee956f115d3846acf0ee0806451807b0aa96d2f8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/1773904
Reviewed-by: Dirk Pranke <dpranke@chromium.org>
Commit-Queue: Elly Fong-Jones <ellyjones@chromium.org>
changes/04/1773904/2
Elly Fong-Jones 6 years ago committed by Commit Bot
parent cea9f9db63
commit ee8d9ce83d

@ -610,3 +610,12 @@ class Database(object):
lambda owner: total_costs_by_owner[owner] == lowest_cost,
total_costs_by_owner)
return random.Random().choice(lowest_cost_owners)
def owners_rooted_at_file(self, filename):
"""Returns a set of all owners transitively listed in filename.
This function returns a set of all the owners either listed in filename, or
in a file transitively included by filename. Lines that are not plain owners
(i.e. per-file owners) are ignored.
"""
return self._read_just_the_owners(filename)

@ -388,6 +388,14 @@ class OwnersDatabaseTest(_BaseTestCase):
john: {'': 'comment preceeded by empty line'},
peter: {'': 'comment in the middle'}})
def test_owners_rooted_at_file(self):
self.files['/foo/OWNERS'] = owners_file(darin, file='//bar/OWNERS')
self.files['/bar/OWNERS'] = owners_file(john,
lines=['per-file nope.cc=' + ben])
db = self.db()
self.assertEqual(db.owners_rooted_at_file('foo/OWNERS'),
set([john, darin]))
class ReviewersForTest(_BaseTestCase):
def assert_reviewers_for(self, files, potential_suggested_reviewers,

Loading…
Cancel
Save