From ee8d9ce83d7c26d09283efc88d381bd2505bf836 Mon Sep 17 00:00:00 2001 From: Elly Fong-Jones Date: Wed, 28 Aug 2019 20:32:21 +0000 Subject: [PATCH] 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 Commit-Queue: Elly Fong-Jones --- owners.py | 9 +++++++++ tests/owners_unittest.py | 8 ++++++++ 2 files changed, 17 insertions(+) diff --git a/owners.py b/owners.py index 602fd3114..b8578023c 100644 --- a/owners.py +++ b/owners.py @@ -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) diff --git a/tests/owners_unittest.py b/tests/owners_unittest.py index 5998c46d9..bc8478698 100755 --- a/tests/owners_unittest.py +++ b/tests/owners_unittest.py @@ -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,