From 48c947534d1b5569822d540a2d7447a20a651c81 Mon Sep 17 00:00:00 2001 From: Josip Sokcevic Date: Thu, 15 Jul 2021 11:29:59 +0000 Subject: [PATCH] Add presubmit notice if buganizer bug is malformed If user enters buganizer bug prefixed with b/, warn user that b: is expected. R=apolito@google.com Bug: 1226474 Change-Id: Ifbced843f9eecc00560cc273ae06bff9d435a815 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/3016587 Reviewed-by: Anthony Polito Commit-Queue: Josip Sokcevic Auto-Submit: Josip Sokcevic --- presubmit_canned_checks.py | 8 +++++++- tests/presubmit_unittest.py | 10 +++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/presubmit_canned_checks.py b/presubmit_canned_checks.py index a14c9202b..0ef5bb987 100644 --- a/presubmit_canned_checks.py +++ b/presubmit_canned_checks.py @@ -50,7 +50,13 @@ OFF_UNLESS_MANUALLY_ENABLED_LINT_FILTERS = [ def CheckChangeHasBugField(input_api, output_api): """Requires that the changelist have a Bug: field.""" - if input_api.change.BugsFromDescription(): + bugs = input_api.change.BugsFromDescription() + if bugs: + if any(b.startswith('b/') for b in bugs): + return [ + output_api.PresubmitNotifyResult( + 'Buganizer bugs should be prefixed with b:, not b/.') + ] return [] else: return [output_api.PresubmitNotifyResult( diff --git a/tests/presubmit_unittest.py b/tests/presubmit_unittest.py index 402f1c295..e5a0d0660 100755 --- a/tests/presubmit_unittest.py +++ b/tests/presubmit_unittest.py @@ -1993,9 +1993,13 @@ class CannedChecksUnittest(PresubmitTestsBase): def testCannedCheckChangeHasBugField(self): self.DescriptionTest(presubmit_canned_checks.CheckChangeHasBugField, - 'Foo\nBUG=1234', 'Foo\n', - presubmit.OutputApi.PresubmitNotifyResult, - False) + 'Foo\nBUG=b:1234', 'Foo\n', + presubmit.OutputApi.PresubmitNotifyResult, False) + + def testCannedCheckChangeHasBugFieldWithBuganizerSlash(self): + self.DescriptionTest(presubmit_canned_checks.CheckChangeHasBugField, + 'Foo\nBUG=b:1234', 'Foo\nBUG=b/1234', + presubmit.OutputApi.PresubmitNotifyResult, False) def testCannedCheckChangeHasNoUnwantedTags(self): self.DescriptionTest(presubmit_canned_checks.CheckChangeHasNoUnwantedTags,