diff --git a/presubmit_canned_checks.py b/presubmit_canned_checks.py index c7ee5a0ce..cf358b10c 100644 --- a/presubmit_canned_checks.py +++ b/presubmit_canned_checks.py @@ -1176,17 +1176,8 @@ def CheckOwners( owner_email = owner_email or input_api.change.author_email - finder = input_api.owners_finder( - affected_files, - input_api.change.RepositoryRoot(), - owner_email, - reviewers, - fopen=open, - os_path=input_api.os_path, - email_postfix='', - disable_color=True, - override_files=input_api.change.OriginalOwnersFiles()) - missing_files = finder.unreviewed_files + missing_files = owners_db.files_not_covered_by( + affected_files, reviewers.union([owner_email])) affects_owners = any('OWNERS' in name for name in missing_files) if input_api.is_committing: @@ -1216,15 +1207,9 @@ def CheckOwners( output_list.append(output_fn('TBR for OWNERS files are ignored.')) if not input_api.is_committing: suggested_owners = owners_db.reviewers_for(missing_files, owner_email) - owners_with_comments = [] - def RecordComments(text): - owners_with_comments.append(finder.print_indent() + text) - finder.writeln = RecordComments - for owner in suggested_owners: - finder.print_comments(owner) output_list.append(output_fn('Suggested OWNERS: ' + '(Use "git-cl owners" to interactively select owners.)\n %s' % - ('\n '.join(owners_with_comments)))) + ('\n '.join(suggested_owners)))) return output_list if input_api.is_committing and not reviewers: diff --git a/tests/presubmit_unittest.py b/tests/presubmit_unittest.py index 4cab06be5..359d5f688 100755 --- a/tests/presubmit_unittest.py +++ b/tests/presubmit_unittest.py @@ -2721,14 +2721,9 @@ the current line as well! fake_db = mock.MagicMock(owners.Database) fake_db.email_regexp = input_api.re.compile(owners.BASIC_EMAIL_REGEXP) - input_api.owners_db = fake_db + fake_db.files_not_covered_by.return_value = uncovered_files - fake_finder = mock.MagicMock(owners_finder.OwnersFinder) - fake_finder.unreviewed_files = uncovered_files - fake_finder.print_indent = lambda: '' - # pylint: disable=unnecessary-lambda - fake_finder.print_comments = lambda owner: fake_finder.writeln(owner) - input_api.owners_finder = lambda *args, **kwargs: fake_finder + input_api.owners_db = fake_db input_api.is_committing = is_committing input_api.tbr = tbr input_api.dry_run = dry_run @@ -2775,6 +2770,11 @@ the current line as well! self.assertRegexpMatches(sys.stdout.getvalue(), expected_output) else: self.assertEqual(sys.stdout.getvalue(), expected_output) + + files_not_covered_by_calls = fake_db.files_not_covered_by.mock_calls + if len(files_not_covered_by_calls): + actual_reviewers = fake_db.files_not_covered_by.mock_calls[0][1][1] + self.assertIn(change.author_email, actual_reviewers) sys.stdout.truncate(0) def testCannedCheckOwners_DryRun(self):