Commit ee8d9ce8 authored by Elly Fong-Jones's avatar Elly Fong-Jones Committed by Commit Bot

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/+/1773904Reviewed-by: 's avatarDirk Pranke <dpranke@chromium.org>
Commit-Queue: Elly Fong-Jones <ellyjones@chromium.org>
parent cea9f9db
......@@ -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,
......
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