Skip to content

Commit

Permalink
ci(commitlint): check PR number presence in merge commits (reanahub#810)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdonadoni committed Aug 6, 2024
1 parent 69eb86b commit f1291ed
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
- name: Check commit message compliance of the pull request
if: github.event_name == 'pull_request'
run: |
./run-tests.sh --check-commitlint ${{ github.event.pull_request.head.sha }}~${{ github.event.pull_request.commits }} ${{ github.event.pull_request.head.sha }} ${{ github.event.pull_request.number }}
./run-tests.sh --check-commitlint ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }} ${{ github.event.pull_request.number }}
lint-shellcheck:
runs-on: ubuntu-24.04
Expand Down
19 changes: 11 additions & 8 deletions run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,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
Expand Down

0 comments on commit f1291ed

Please sign in to comment.