Commit b24ca5ac authored by Edward Lemur's avatar Edward Lemur Committed by LUCI CQ

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/+/2005050Reviewed-by: 's avatarAnthony Polito <apolito@google.com>
Commit-Queue: Edward Lesmes <ehmaldonado@chromium.org>
parent 98cfac11
......@@ -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, <files> 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(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment