mirror of
https://github.com/apache/nuttx.git
synced 2026-06-01 16:59:28 +08:00
tools/checkpatch.sh: Add support for breaking change commit message enforcement
- Introduced a new flag '-b' to enforce breaking change format in commit messages. - Added checks to ensure that breaking change commits start with '!' and contain 'BREAKING CHANGE:' in the body before 'Signed-off-by'. - Updated usage instructions to reflect the new breaking change option. Signed-off-by: Arjav Patel <arjav1528@gmail.com>
This commit is contained in:
+32
-1
@@ -32,6 +32,7 @@ range=0
|
|||||||
spell=0
|
spell=0
|
||||||
encoding=0
|
encoding=0
|
||||||
message=0
|
message=0
|
||||||
|
breaking_change=0
|
||||||
|
|
||||||
# CMake
|
# CMake
|
||||||
cmake_warning_once=0
|
cmake_warning_once=0
|
||||||
@@ -57,6 +58,7 @@ usage() {
|
|||||||
echo "-r range check only (coupled with -p or -g)"
|
echo "-r range check only (coupled with -p or -g)"
|
||||||
echo "-p <patch file names> (default)"
|
echo "-p <patch file names> (default)"
|
||||||
echo "-m Check commit message (coupled with -g)"
|
echo "-m Check commit message (coupled with -g)"
|
||||||
|
echo "-b Enforce breaking change format when checking commit message (requires -m -g; use when PR has breaking change label)"
|
||||||
echo "-g <commit list>"
|
echo "-g <commit list>"
|
||||||
echo "-f <file list>"
|
echo "-f <file list>"
|
||||||
echo "-x format supported files (only .py, requires: pip install black)"
|
echo "-x format supported files (only .py, requires: pip install black)"
|
||||||
@@ -286,13 +288,14 @@ check_msg() {
|
|||||||
num_lines=0
|
num_lines=0
|
||||||
max_line_len=80
|
max_line_len=80
|
||||||
min_num_lines=5
|
min_num_lines=5
|
||||||
|
breaking_change_found=0
|
||||||
|
|
||||||
first=$(head -n1 <<< "$msg")
|
first=$(head -n1 <<< "$msg")
|
||||||
|
|
||||||
# check for Merge line and remove from parsed string
|
# check for Merge line and remove from parsed string
|
||||||
if [[ $first == *Merge* ]]; then
|
if [[ $first == *Merge* ]]; then
|
||||||
msg="$(echo "$msg" | tail -n +2)"
|
msg="$(echo "$msg" | tail -n +2)"
|
||||||
first=$(head -n2 <<< "$msg")
|
first=$(head -n1 <<< "$msg")
|
||||||
fi
|
fi
|
||||||
|
|
||||||
while IFS= read -r REPLY; do
|
while IFS= read -r REPLY; do
|
||||||
@@ -311,7 +314,15 @@ check_msg() {
|
|||||||
fail=1
|
fail=1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [[ $REPLY =~ ^BREAKING\ CHANGE: ]]; then
|
||||||
|
breaking_change_found=1
|
||||||
|
fi
|
||||||
|
|
||||||
if [[ $REPLY =~ ^Signed-off-by ]]; then
|
if [[ $REPLY =~ ^Signed-off-by ]]; then
|
||||||
|
if [ $breaking_change != 0 ] && [ $breaking_change_found == 0 ]; then
|
||||||
|
echo "❌ BREAKING CHANGE: must appear in the commit body before Signed-off-by (see CONTRIBUTING.md 1.13)"
|
||||||
|
fail=1
|
||||||
|
fi
|
||||||
signedoffby_found=1
|
signedoffby_found=1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -328,6 +339,23 @@ check_msg() {
|
|||||||
fail=1
|
fail=1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
second=$(echo "$msg" | sed -n '2p')
|
||||||
|
if [ $num_lines -ge 2 ] && ! [[ "$second" =~ ^[[:space:]]*$ ]]; then
|
||||||
|
echo "❌ Commit subject must be followed by a blank line"
|
||||||
|
fail=1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ $breaking_change != 0 ]; then
|
||||||
|
if [[ "${first:0:1}" != "!" ]]; then
|
||||||
|
echo "❌ Breaking change commit subject must start with '!' (e.g. '!subsystem: description')"
|
||||||
|
fail=1
|
||||||
|
fi
|
||||||
|
if [ $breaking_change_found == 0 ]; then
|
||||||
|
echo "❌ Breaking change commit must contain 'BREAKING CHANGE:' in the body before Signed-off-by (see CONTRIBUTING.md 1.13)"
|
||||||
|
fail=1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
if ! [ $signedoffby_found == 1 ]; then
|
if ! [ $signedoffby_found == 1 ]; then
|
||||||
echo "❌ Missing Signed-off-by"
|
echo "❌ Missing Signed-off-by"
|
||||||
fail=1
|
fail=1
|
||||||
@@ -383,6 +411,9 @@ while [ ! -z "$1" ]; do
|
|||||||
-m )
|
-m )
|
||||||
message=1
|
message=1
|
||||||
;;
|
;;
|
||||||
|
-b )
|
||||||
|
breaking_change=1
|
||||||
|
;;
|
||||||
-g )
|
-g )
|
||||||
check=check_commit
|
check=check_commit
|
||||||
;;
|
;;
|
||||||
|
|||||||
Reference in New Issue
Block a user