From b24ca5ac742e6c65e949b2f7f83a2d9b95cff3e9 Mon Sep 17 00:00:00 2001 From: Edward Lemur Date: Fri, 17 Jan 2020 19:28:21 +0000 Subject: [PATCH] presubmit_support: Initialize Gerrit object when gerrit URL is given. Only gerrit_url is needed to initialize gerrit_obj. This will be needed for git cl to call presubmit support as a script. Bug: 1042324 Change-Id: I79d78fb67465f989755bf8c8ceb48d665464fa05 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/2005050 Reviewed-by: Anthony Polito Commit-Queue: Edward Lesmes --- presubmit_support.py | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/presubmit_support.py b/presubmit_support.py index ce839e546..fadc32d0c 100755 --- a/presubmit_support.py +++ b/presubmit_support.py @@ -1770,6 +1770,21 @@ def main(argv=None): options = parser.parse_args(argv) + gerrit_obj = None + if options.gerrit_url: + gerrit_obj = GerritAccessor(urlparse.urlparse(options.gerrit_url).netloc) + if options.gerrit_fetch: + if not options.gerrit_url or not options.issue or not options.patchset: + parser.error( + '--gerrit_fetch requires --gerrit_url, --issue and --patchset.') + + options.author = gerrit_obj.GetChangeOwner(options.issue) + options.description = gerrit_obj.GetChangeDescription( + options.issue, options.patchset) + + logging.info('Got author: "%s"', options.author) + logging.info('Got description: """\n%s\n"""', options.description) + if options.verbose >= 2: logging.basicConfig(level=logging.DEBUG) elif options.verbose: @@ -1782,16 +1797,6 @@ def main(argv=None): parser.error('For unversioned directory, is not optional.') logging.info('Found %d file(s).', len(files)) - gerrit_obj = None - if options.gerrit_url and options.gerrit_fetch: - assert options.issue and options.patchset - gerrit_obj = GerritAccessor(urlparse.urlparse(options.gerrit_url).netloc) - options.author = gerrit_obj.GetChangeOwner(options.issue) - options.description = gerrit_obj.GetChangeDescription(options.issue, - options.patchset) - logging.info('Got author: "%s"', options.author) - logging.info('Got description: """\n%s\n"""', options.description) - try: with canned_check_filter(options.skip_canned): results = DoPresubmitChecks(