aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Anthony <nickanthony@google.com>2020-06-19 11:40:34 -0400
committerNick Anthony <nickanthony@google.com>2020-06-19 12:22:27 -0400
commitd7363ec0659ab50df745f305d098ada4ca0adb8a (patch)
tree6308b95ad785054d3ae5ed2a62972ba058ef0b7a
parentbf70aed7478925fb510a3622e16195d699223e4c (diff)
downloadrepohooks-d7363ec0659ab50df745f305d098ada4ca0adb8a.tar.gz
Fix regex in commit_msg_relnote_for_current_txt repo hookandroid-r-beta-3android-r-beta-2
The current (incorrect) regex only enforces a Relnote tag for current.txt files in the root directory of the repo. However, current.txt can be in any repo subdirectory, so we need to enforce it everywhere. This change removes the up carrot in the regex that enforces matches must start at the line start. Bug: 159449967 Test: ./pre-upload.py (with commit_msg_relnote_for_current_txt = true) Change-Id: I7555398df6edaf410af60ce0def05894ef53ea11
-rw-r--r--rh/hooks.py2
-rwxr-xr-xrh/hooks_unittest.py42
2 files changed, 37 insertions, 7 deletions
diff --git a/rh/hooks.py b/rh/hooks.py
index 223323a..7c13bf1 100644
--- a/rh/hooks.py
+++ b/rh/hooks.py
@@ -682,7 +682,7 @@ def check_commit_msg_relnote_for_current_txt(project, commit, desc, diff,
filtered = _filter_diff(
diff,
- [r'^(public_plus_experimental_current|current)\.txt$']
+ [r'(^|/)(public_plus_experimental_current|current)\.txt$']
)
# If the commit does not contain a change to *current.txt, then this repo
# hook check no longer applies.
diff --git a/rh/hooks_unittest.py b/rh/hooks_unittest.py
index 4c44b21..373e09f 100755
--- a/rh/hooks_unittest.py
+++ b/rh/hooks_unittest.py
@@ -575,11 +575,16 @@ class BuiltinHooksTests(unittest.TestCase):
def test_commit_msg_relnote_for_current_txt(self, _mock_check, _mock_run):
"""Verify the commit_msg_relnote_for_current_txt builtin hook."""
- diff_without_current_txt = ['foo.txt',
+ diff_without_current_txt = ['bar/foo.txt',
'foo.cpp',
'foo.java',
- 'current.java']
+ 'foo_current.java',
+ 'foo_current.txt',
+ 'baz/current.java',
+ 'baz/foo_current.txt']
diff_with_current_txt = diff_without_current_txt + ['current.txt']
+ diff_with_subdir_current_txt = \
+ diff_without_current_txt + ['foo/current.txt']
diff_with_experimental_current_txt = \
diff_without_current_txt + ['public_plus_experimental_current.txt']
# Check some good messages.
@@ -611,7 +616,22 @@ class BuiltinHooksTests(unittest.TestCase):
'Bug: 1234'),
),
files=diff_with_experimental_current_txt,
- )
+ )
+ # Check some good messages.
+ self._test_commit_messages(
+ rh.hooks.check_commit_msg_relnote_for_current_txt,
+ True,
+ (
+ 'subj\n\nRelnote: This is a release note\n',
+ 'subj\n\nRelnote: This is a release note.\n\nChange-Id: 1234',
+ ('subj\n\nRelnote: This is release note 1 with\n'
+ 'an incorrectly formatted second line.\n\n'
+ 'Relnote: "This is release note 2, and it\n'
+ 'contains a correctly formatted second line."\n'
+ 'Bug: 1234'),
+ ),
+ files=diff_with_subdir_current_txt,
+ )
# Check some good messages.
self._test_commit_messages(
rh.hooks.check_commit_msg_relnote_for_current_txt,
@@ -628,7 +648,7 @@ class BuiltinHooksTests(unittest.TestCase):
'Bug: 1234'),
),
files=diff_without_current_txt,
- )
+ )
# Check some bad messages.
self._test_commit_messages(
rh.hooks.check_commit_msg_relnote_for_current_txt,
@@ -638,7 +658,7 @@ class BuiltinHooksTests(unittest.TestCase):
'subj\nBug: 12345\nChange-Id: 1234',
),
files=diff_with_current_txt,
- )
+ )
# Check some bad messages.
self._test_commit_messages(
rh.hooks.check_commit_msg_relnote_for_current_txt,
@@ -648,7 +668,17 @@ class BuiltinHooksTests(unittest.TestCase):
'subj\nBug: 12345\nChange-Id: 1234',
),
files=diff_with_experimental_current_txt,
- )
+ )
+ # Check some bad messages.
+ self._test_commit_messages(
+ rh.hooks.check_commit_msg_relnote_for_current_txt,
+ False,
+ (
+ 'subj'
+ 'subj\nBug: 12345\nChange-Id: 1234',
+ ),
+ files=diff_with_subdir_current_txt,
+ )
def test_cpplint(self, mock_check, _mock_run):
"""Verify the cpplint builtin hook."""