aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Anthony <nickanthony@google.com>2020-06-11 20:07:11 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2020-06-11 20:07:11 +0000
commit3ccf437583f7dcc8d53301256c6effdea865e9e3 (patch)
tree45354e9482e1916af07a4eeaa4b6f34c85050ac8
parent3a36e38a5d19d4076d63ea630a85b02f070a3e37 (diff)
parentbf70aed7478925fb510a3622e16195d699223e4c (diff)
downloadrepohooks-3ccf437583f7dcc8d53301256c6effdea865e9e3.tar.gz
hooks: require a Relnote field when changing current.txt am: bf70aed747
Original change: https://android-review.googlesource.com/c/platform/tools/repohooks/+/1274027 Change-Id: Icd6bbf51132eff965b966bc195ad05ab11db307a
-rw-r--r--README.md3
-rw-r--r--rh/hooks.py57
-rwxr-xr-xrh/hooks_unittest.py77
3 files changed, 137 insertions, 0 deletions
diff --git a/README.md b/README.md
index 83572ac..d35a4c4 100644
--- a/README.md
+++ b/README.md
@@ -181,6 +181,9 @@ canned hooks already included geared towards AOSP style guidelines.
* `commit_msg_relnote_field_format`: Check for possible misspellings of the
`Relnote:` field and that multiline release notes are properly formatted with
quotes.
+* `commit_msg_relnote_for_current_txt`: Check that CLs with changes to
+ current.txt or public_plus_experimental_current.txt also contain a
+ `Relnote:` field in the commit message.
* `commit_msg_test_field`: Require a `Test:` line.
* `cpplint`: Run through the cpplint tool (for C++ code).
* `gofmt`: Run Go code through `gofmt`.
diff --git a/rh/hooks.py b/rh/hooks.py
index 68422b1..223323a 100644
--- a/rh/hooks.py
+++ b/rh/hooks.py
@@ -648,6 +648,61 @@ def check_commit_msg_relnote_field_format(project, commit, desc, _diff,
return ret
+RELNOTE_REQUIRED_CURRENT_TXT_MSG = """\
+Commit contains a change to current.txt or public_plus_experimental_current.txt,
+but the commit message does not contain the required `Relnote:` tag. It must
+match the regex:
+
+ %s
+
+The Relnote: stanza is free-form and should describe what developers need to
+know about your change. If you are making infrastructure changes, you
+can set the Relnote: stanza to be "N/A" for the commit to not be included
+in release notes.
+
+Some examples:
+
+Relnote: "Added a new API `Class#isBetter` to determine whether or not the
+class is better"
+Relnote: Fixed an issue where the UI would hang on a double tap.
+Relnote: N/A
+
+Check the git history for more examples.
+"""
+
+def check_commit_msg_relnote_for_current_txt(project, commit, desc, diff,
+ options=None):
+ """Check changes to current.txt contain the 'Relnote:' stanza."""
+ field = 'Relnote'
+ regex = r'^%s: .+$' % (field,)
+ check_re = re.compile(regex, re.IGNORECASE)
+
+ if options.args():
+ raise ValueError('commit msg %s check takes no options' % (field,))
+
+ filtered = _filter_diff(
+ diff,
+ [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.
+ if not filtered:
+ return None
+
+ found = []
+ for line in desc.splitlines():
+ if check_re.match(line):
+ found.append(line)
+
+ if not found:
+ error = RELNOTE_REQUIRED_CURRENT_TXT_MSG % (regex)
+ else:
+ return None
+
+ return [rh.results.HookResult('commit msg: "%s:" check' % (field,),
+ project, commit, error=error)]
+
+
def check_cpplint(project, commit, _desc, diff, options=None):
"""Run cpplint."""
# This list matches what cpplint expects. We could run on more (like .cxx),
@@ -812,6 +867,8 @@ BUILTIN_HOOKS = {
'commit_msg_prebuilt_apk_fields': check_commit_msg_prebuilt_apk_fields,
'commit_msg_test_field': check_commit_msg_test_field,
'commit_msg_relnote_field_format': check_commit_msg_relnote_field_format,
+ 'commit_msg_relnote_for_current_txt':
+ check_commit_msg_relnote_for_current_txt,
'cpplint': check_cpplint,
'gofmt': check_gofmt,
'google_java_format': check_google_java_format,
diff --git a/rh/hooks_unittest.py b/rh/hooks_unittest.py
index 0442f4e..4c44b21 100755
--- a/rh/hooks_unittest.py
+++ b/rh/hooks_unittest.py
@@ -573,6 +573,83 @@ class BuiltinHooksTests(unittest.TestCase):
'Bug: 1234'),
))
+ 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',
+ 'foo.cpp',
+ 'foo.java',
+ 'current.java']
+ diff_with_current_txt = diff_without_current_txt + ['current.txt']
+ diff_with_experimental_current_txt = \
+ diff_without_current_txt + ['public_plus_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_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_experimental_current_txt,
+ )
+ # Check some good messages.
+ self._test_commit_messages(
+ rh.hooks.check_commit_msg_relnote_for_current_txt,
+ True,
+ (
+ 'subj',
+ 'subj\nBug: 12345\nChange-Id: 1234',
+ '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_without_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_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_experimental_current_txt,
+ )
+
def test_cpplint(self, mock_check, _mock_run):
"""Verify the cpplint builtin hook."""
self._test_file_filter(mock_check, rh.hooks.check_cpplint,