Skip to content

Commit

Permalink
ci(commitlint): improve checking of merge commits (#803)
Browse files Browse the repository at this point in the history
  • Loading branch information
tiborsimko committed Jun 3, 2024
1 parent b4f4633 commit 16e5542
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .commitlintrc.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
rules:
body-case: [2, always, sentence-case]
body-full-stop: [2, always]
body-full-stop: [1, always]
body-leading-blank: [2, always]
body-max-line-length: [2, always, 72]
footer-leading-blank: [2, always]
Expand Down
18 changes: 14 additions & 4 deletions run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,25 @@ check_commitlint () {
npx commitlint --from="$from" --to="$to"
found=0
while IFS= read -r line; do
if echo "$line" | grep -qP "\(\#$pr\)$"; then
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}')
if [ "$commit_number_of_parents" -gt 1 ]; then
if echo "$commit_title" | grep -qP "^chore\(.*\): merge "; then
break
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 "$line" | grep -qP "^chore\(.*\): release"; then
elif echo "$commit_title" | grep -qP "\(\#$pr\)$"; then
true
else
echo "✖ Headline does not end by '(#$pr)' PR number: $line"
echo "✖ Headline does not end by '(#$pr)' PR number: $commit_title"
found=1
fi
done < <(git log "$from..$to" --format="%s")
done < <(git log "$from..$to" --format="%H %s")
if [ $found -gt 0 ]; then
exit 1
fi
Expand Down

0 comments on commit 16e5542

Please sign in to comment.