presubmit: support checking new TODO format

R=sokcevic

Bug: 1479023
Change-Id: I6eabb16447526fbc8de83b823763888aff1a8249
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/4847314
Reviewed-by: Josip Sokcevic <sokcevic@chromium.org>
Commit-Queue: Josip Sokcevic <sokcevic@chromium.org>
Auto-Submit: Yiwei Zhang <yiwzhang@google.com>
changes/14/4847314/2
Yiwei Zhang 2 years ago committed by LUCI CQ
parent c56d8196e1
commit 7a69b031d5

@ -539,12 +539,16 @@ def CheckChangeHasNoTabs(input_api, output_api, source_file_filter=None):
def CheckChangeTodoHasOwner(input_api, output_api, source_file_filter=None):
"""Checks that the user didn't add TODO(name) without an owner."""
unowned_todo = input_api.re.compile('TO' 'DO[^(]')
"""Checks that the user didn't add `TODO(name)` or `TODO: name -` without
an owner.
"""
legacyTODO = '\\s*\\(.+\\)\\s*:'
modernTODO = ':\\s*[^\\s]+\\s*\\-'
unowned_todo = input_api.re.compile('TODO(?!(%s|%s))' %
(legacyTODO, modernTODO))
errors = _FindNewViolationsOfRule(lambda _, x: not unowned_todo.search(x),
input_api, source_file_filter)
errors = ['Found TO' 'DO with no owner in ' + x for x in errors]
errors = ['Found TODO with no owner in ' + x for x in errors]
if errors:
return [output_api.PresubmitPromptWarning('\n'.join(errors))]
return []

@ -2049,6 +2049,9 @@ class CannedChecksUnittest(PresubmitTestsBase):
presubmit.OutputApi.PresubmitPromptWarning)
def testCheckChangeTodoHasOwner(self):
self.ContentTest(presubmit_canned_checks.CheckChangeTodoHasOwner,
"TODO: foo - bar", None, "TODO: bar", None,
presubmit.OutputApi.PresubmitPromptWarning)
self.ContentTest(presubmit_canned_checks.CheckChangeTodoHasOwner,
"TODO(foo): bar", None, "TODO: bar", None,
presubmit.OutputApi.PresubmitPromptWarning)

Loading…
Cancel
Save