From c68720b3db365c59f154d6847536786654476911 Mon Sep 17 00:00:00 2001 From: Marco Donadoni Date: Tue, 6 Aug 2024 11:39:04 +0200 Subject: [PATCH] ci(commitlint): check PR number presence in merge commits (#592) --- run-tests.sh | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/run-tests.sh b/run-tests.sh index facd04dd..63a31317 100755 --- a/run-tests.sh +++ b/run-tests.sh @@ -59,20 +59,23 @@ check_commitlint () { commit_hash=$(echo "$line" | cut -d ' ' -f 1) commit_title=$(echo "$line" | cut -d ' ' -f 2-) commit_number_of_parents=$(git rev-list --parents "$commit_hash" -n1 | awk '{print NF-1}') + # (i) skip checking release commits generated by Release Please + if [ "$commit_number_of_parents" -le 1 ] && echo "$commit_title" | grep -qP "^chore\(.*\): release"; then + continue + fi + # (ii) check presence of PR number + if ! echo "$commit_title" | grep -qP "\(\#$pr\)$"; then + echo "✖ Headline does not end by '(#$pr)' PR number: $commit_title" + found=1 + fi + # (iii) check absence of merge commits in feature branches if [ "$commit_number_of_parents" -gt 1 ]; then if echo "$commit_title" | grep -qP "^chore\(.*\): merge "; then - break + break # skip checking maint-to-master merge commits else echo "✖ Merge commits are not allowed in feature branches: $commit_title" found=1 fi - elif echo "$commit_title" | grep -qP "^chore\(.*\): release"; then - true - elif echo "$commit_title" | grep -qP "\(\#$pr\)$"; then - true - else - echo "✖ Headline does not end by '(#$pr)' PR number: $commit_title" - found=1 fi done < <(git log "$from..$to" --format="%H %s") if [ $found -gt 0 ]; then