Skip to content

Commit

Permalink
ci: Add script to sanitize git commit messages
Browse files Browse the repository at this point in the history
* Introduced `sanatizer-git-commit-messages` script to enforce commit
  message standards.
* The script checks for a valid format in commit messages, ensuring
  they start with a capitalized word followed by a colon and a space.
* It verifies the presence of required keywords: `Change-type:` or
  `Maintenance-type:`.

Maintenance-type: ci
  • Loading branch information
psaavedra committed Feb 21, 2025
1 parent 1f445c8 commit e7e9887
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions .github/scripts/sanatizer-git-commit-messages
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/bin/bash

set -e

echo "Running git commit log messages check:"

error_found=0

baseref="main"
headref="HEAD"

git fetch origin $baseref 2>&1 > /dev/null

if [[ -n "${GITHUB_HEAD_REF}" ]]; then
headref="origin/${GITHUB_HEAD_REF}"
git fetch origin ${GITHUB_HEAD_REF} 2>&1 > /dev/null
fi

# Get commit messages
commits=$(git log origin/${baseref}..${headref} --pretty=format:"%s")
echo "$commits" > commit_messages.txt

# Check commit messages format
while IFS= read -r line; do
if ! [[ $line =~ ^[a-zA-Z]+:\ [a-zA-Z]+ ]]; then
echo "Invalid commit message: $line"
error_found=1
fi
done < commit_messages.txt

# Get full commit messages
commits=$(git log origin/${baseref}..${headref} --pretty=format:"%B")
echo "$commits" > commit_messages.txt

# Check for required keywords
if ! grep -qE 'Change-type:|Maintenance-type:' commit_messages.txt; then
echo "Error: No commit message contains 'Change-type:' or 'Maintenance-type:'."
error_found=1
fi

rm commit_messages.txt
# Exit with the appropriate status
exit $error_found

0 comments on commit e7e9887

Please sign in to comment.