From 76f5fc6cd95efaca49b8f0459f1bf8468a97bc8c Mon Sep 17 00:00:00 2001 From: Jochen Eisinger Date: Fri, 7 Apr 2017 16:27:46 +0200 Subject: [PATCH] Also print comments found in files during presubmit owners suggestion R=dpranke@chromium.org BUG=694222 Change-Id: I5676db2283dd43378293bc9bb32f71e0a1225806 Reviewed-on: https://chromium-review.googlesource.com/471609 Reviewed-by: Dirk Pranke Commit-Queue: Jochen Eisinger --- presubmit_canned_checks.py | 13 ++++++++++++- presubmit_support.py | 2 ++ tests/presubmit_unittest.py | 13 +++++++++++-- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/presubmit_canned_checks.py b/presubmit_canned_checks.py index d6434ede5..11f18b1f5 100644 --- a/presubmit_canned_checks.py +++ b/presubmit_canned_checks.py @@ -903,9 +903,20 @@ def CheckOwners(input_api, output_api, source_file_filter=None): (needed, '\n '.join(sorted(missing_files))))] if not input_api.is_committing: suggested_owners = owners_db.reviewers_for(missing_files, owner_email) + finder = input_api.owners_finder(missing_files, + input_api.change.RepositoryRoot(), + owner_email, + fopen=file, os_path=input_api.os_path, + email_postfix='', disable_color=True) + 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(suggested_owners or [])))) + ('\n '.join(owners_with_comments)))) return output_list if input_api.is_committing and not reviewers: diff --git a/presubmit_support.py b/presubmit_support.py index b35d82645..f914f0fe3 100755 --- a/presubmit_support.py +++ b/presubmit_support.py @@ -45,6 +45,7 @@ import fix_encoding import gclient_utils import gerrit_util import owners +import owners_finder import presubmit_canned_checks import rietveld import scm @@ -423,6 +424,7 @@ class InputApi(object): # in order to be able to handle wildcard OWNERS files? self.owners_db = owners.Database(change.RepositoryRoot(), fopen=file, os_path=self.os_path) + self.owners_finder = owners_finder.OwnersFinder self.verbose = verbose self.Command = CommandData diff --git a/tests/presubmit_unittest.py b/tests/presubmit_unittest.py index 76ea971cc..132840710 100755 --- a/tests/presubmit_unittest.py +++ b/tests/presubmit_unittest.py @@ -23,6 +23,7 @@ sys.path.insert(0, _ROOT) from testing_support.super_mox import mox, SuperMoxTestBase import owners +import owners_finder import subprocess2 as subprocess import presubmit_support as presubmit import rietveld @@ -163,8 +164,8 @@ class PresubmitUnittest(PresubmitTestsBase): 'auth', 'cPickle', 'cpplint', 'cStringIO', 'contextlib', 'canned_check_filter', 'fix_encoding', 'fnmatch', 'gclient_utils', 'glob', 'inspect', 'json', 'load_files', 'logging', - 'marshal', 'normpath', 'optparse', 'os', 'owners', 'pickle', - 'presubmit_canned_checks', 'random', 're', 'rietveld', 'scm', + 'marshal', 'normpath', 'optparse', 'os', 'owners', 'owners_finder', + 'pickle', 'presubmit_canned_checks', 'random', 're', 'rietveld', 'scm', 'subprocess', 'sys', 'tempfile', 'time', 'traceback', 'types', 'unittest', 'urllib2', 'warn', 'multiprocessing', 'DoGetTryMasters', 'GetTryMastersExecuter', 'itertools', 'urlparse', 'gerrit_util', @@ -996,6 +997,7 @@ class InputApiUnittest(PresubmitTestsBase): 'os_path', 'os_stat', 'owners_db', + 'owners_finder', 'pickle', 'platform', 'python_executable', @@ -2250,6 +2252,7 @@ class CannedChecksUnittest(PresubmitTestsBase): change.author_email = 'john@example.com' change.R = ','.join(manually_specified_reviewers) change.TBR = '' + change.RepositoryRoot = lambda: None affected_file = self.mox.CreateMock(presubmit.GitAffectedFile) input_api = self.MockInputApi(change, False) if gerrit_response: @@ -2260,6 +2263,12 @@ class CannedChecksUnittest(PresubmitTestsBase): fake_db = self.mox.CreateMock(owners.Database) fake_db.email_regexp = input_api.re.compile(owners.BASIC_EMAIL_REGEXP) input_api.owners_db = fake_db + + fake_finder = self.mox.CreateMock(owners_finder.OwnersFinder) + 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.is_committing = is_committing input_api.tbr = tbr input_api.dry_run = dry_run