This repository has been archived on 2024-07-19. You can view files and clone it, but cannot push or open issues or pull requests.
works-on-my-machine/script/lint-commits

38 lines
1,016 B
Text
Raw Permalink Normal View History

#!/usr/bin/bash
#
# This loosely implements the commit message linting check described by
# Conventional Commit (https://www.conventionalcommits.org). Commits merged in
# branches on this repository are expected to meet that general format:
#
# <prefix>: <message>
#
# where <prefix> is one of the prefixes included in the filters below.
#
CURRENT_HEAD=$(git rev-parse HEAD)
COMMITS=$(git log origin/main..$CURRENT_HEAD --oneline --format=%s)
if [[ -z "$COMMITS" ]]; then
echo "No commits."
exit 0
fi
INVALID_COMMITS_FOUND=0
while IFS='\n' read -r line; do
if [[ $line =~ ^"Merge "[0-9a-z]+" into "[0-9a-z]+$ ]]; then
continue
elif [[ ($line =~ ^(test|feat|chore|fix|refactor|wip|docs|build|ci|perf):) ]]; then
echo "VALID - $line"
else
echo "INVALID - $line"
INVALID_COMMITS_FOUND=$((INVALID_COMMITS_FOUND+1))
fi;
done <<< "$COMMITS"
if [[ $INVALID_COMMITS_FOUND -gt 0 ]]; then
echo "$INVALID_COMMITS_FOUND bad commit messages found."
exit 1
fi