name: PR Title Checker
on:
pull_request:
types: [opened, edited, synchronize, reopened]
jobs:
check-pr-title:
runs-on: ubuntu-latest
permissions:
pull-requests: read # Needed for reading PR information
steps:
- name: Check PR Title Format
run: |
PR_TITLE="${{ github.event.pull_request.title }}"
echo "Checking PR title: $PR_TITLE"
# Define valid types based on conventional commits
VALID_TYPES="feat|fix|docs|style|refactor|perf|test|build|ci|chore|revert"
# Check if PR title matches conventional commit format
if [[ ! "$PR_TITLE" =~ ^($VALID_TYPES)(\([a-z0-9-]+\))?!?:[[:space:]] ]]; then
echo "::error::PR title does not follow the Conventional Commits format."
echo "::error::Expected format: 'type(scope): description' or 'type: description'"
echo "::error::Valid types: feat, fix, docs, style, refactor, perf, test, build, ci, chore, revert"
echo "::error::Examples:"
echo "::error:: - 'feat: add new search feature'"
echo "::error:: - 'fix(api): resolve timeout issue'"
echo "::error:: - 'docs: update README'"
exit 1
fi
echo "PR title follows the Conventional Commits format. ✅"