Allow calling tag functions from PostUploadHook

Calling CheckChangeHasNoUnwantedTags and
CheckChangeHasBugFieldFromChange from a PostUploadHook is useful because
it ensures that users will see a message if they add a bad tag when
creating the commit message during upload. Allowing this requires
creating entry points for these functions that take a change parameter
instead of an input_api parameter. It also requires fixing our use of
the deprecated inspect.getargspec function.

In order to not tell users twice (once before and once after upload)
that they haven't used a Bug: tag (it is optional, after all) a flag
to make these suggestions optional is also added.

This change is required in support of crrev.com/c/4490087.

Bug: 1434702
Change-Id: I3fd909a71c6c7d7671d6f986ad60d5375143a2f1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/4519532
Reviewed-by: Josip Sokcevic <sokcevic@chromium.org>
Commit-Queue: Bruce Dawson <brucedawson@chromium.org>
changes/32/4519532/3
Bruce Dawson 2 years ago committed by LUCI CQ
parent 85c13de0be
commit 05ebc9e3e0

@ -67,29 +67,35 @@ _CORP_LINK_KEYWORD = '.corp.google'
### Description checks
def CheckChangeHasBugField(input_api, output_api):
"""Requires that the changelist have a Bug: field."""
bugs = input_api.change.BugsFromDescription()
def CheckChangeHasBugFieldFromChange(change, output_api, show_suggestions=True):
"""Requires that the changelist have a Bug: field. If show_suggestions is
False then only report on incorrect tags, not missing tags."""
bugs = change.BugsFromDescription()
results = []
if bugs:
if any(b.startswith('b/') for b in bugs):
results.append(
output_api.PresubmitNotifyResult(
'Buganizer bugs should be prefixed with b:, not b/.'))
else:
elif show_suggestions:
results.append(
output_api.PresubmitNotifyResult(
'If this change has an associated bug, add Bug: [bug number] or '
'Fixed: [bug number].'))
if 'Fixes' in input_api.change.GitFootersFromDescription():
if 'Fixes' in change.GitFootersFromDescription():
results.append(
output_api.PresubmitError(
'Fixes: is the wrong footer tag, use Fixed: instead.'))
return results
def CheckChangeHasNoUnwantedTags(input_api, output_api):
def CheckChangeHasBugField(input_api, output_api):
return CheckChangeHasBugFieldFromChange(input_api.change, output_api)
def CheckChangeHasNoUnwantedTagsFromChange(change, output_api):
UNWANTED_TAGS = {
'FIXED': {
'why': 'is not supported',
@ -100,12 +106,17 @@ def CheckChangeHasNoUnwantedTags(input_api, output_api):
errors = []
for tag, desc in UNWANTED_TAGS.items():
if tag in input_api.change.tags:
if tag in change.tags:
subs = tag, desc['why'], desc.get('instead', '')
errors.append(('%s= %s. %s' % subs).rstrip())
return [output_api.PresubmitError('\n'.join(errors))] if errors else []
def CheckChangeHasNoUnwantedTags(input_api, output_api):
return CheckChangeHasNoUnwantedTagsFromChange(input_api.change, output_api)
def CheckDoNotSubmitInDescription(input_api, output_api):
"""Checks that the user didn't add 'DO NOT ''SUBMIT' to the CL description.
"""

@ -1437,7 +1437,7 @@ class GetPostUploadExecuter(object):
if function_name not in context:
return {}
post_upload_hook = context[function_name]
if not len(inspect.getargspec(post_upload_hook)[0]) == 3:
if not len(inspect.getfullargspec(post_upload_hook)[0]) == 3:
raise PresubmitFailure(
'Expected function "PostUploadHook" to take three arguments.')
return post_upload_hook(self.gerrit, self.change, OutputApi(False))

Loading…
Cancel
Save