split: update SelectReviewersForFiles to work with repository root

The current implementation relies on the current working directory,
when it traverses the file tree to find the nearest OWNERS. It also
causes an infinite loop when it cannot find any OWNERS.

This CL changes the implementation so that it works
no matter what the cwd is.

Bug: 412904761
Change-Id: Ic4e25217aa64bd2eb6514ccdd486fe3b57a82312
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6484531
Commit-Queue: Scott Lee <ddoman@chromium.org>
Reviewed-by: Gavin Mak <gavinmak@google.com>
This commit is contained in:
Scott Lee
2025-04-24 08:36:02 -07:00
committed by LUCI CQ
parent 829b580b57
commit b128c9967e
2 changed files with 40 additions and 14 deletions

View File

@@ -104,7 +104,6 @@ class SplitClTest(unittest.TestCase):
@mock.patch("os.path.isfile")
def testSelectReviewersForFiles(self, mock_is_file):
mock_is_file.side_effect = self.MockIsFile
owners_client = mock.Mock(SuggestOwners=self.MockSuggestOwners,
EVERYONE="*")
cl = mock.Mock(owners_client=owners_client)
@@ -116,7 +115,7 @@ class SplitClTest(unittest.TestCase):
("M", os.path.join("baz", "owner3", "e.txt"))]
files_split_by_reviewers = split_cl.SelectReviewersForFiles(
cl, "author", files, 0)
cl, "author", files, 0, "")
self.assertEqual(3, len(files_split_by_reviewers.keys()))
info1 = files_split_by_reviewers[tuple(["owner1", "owner2"])]