Skip to content

Commit

Permalink
fix(commit-msg): Correção no regex
Browse files Browse the repository at this point in the history
  • Loading branch information
cfgnunes committed Feb 12, 2025
1 parent 40c6a7d commit 5a28cb9
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions commit-msg.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,16 @@ COMMIT_MSG_FILE=$1
# Read the commit message from the file.
COMMIT_MSG=$(cat "$COMMIT_MSG_FILE")

# Regular expression for validating Conventional Commits.
# Format: <type>(<scope>): <subject>
# Example: feat(auth): add login functionality
CONVENTIONAL_COMMIT_REGEX='^(feat|fix|docs|style|refactor|test|chore|build|ci|perf|revert)(\([a-zA-Z0-9_-]+\))?:\s.*$'
CONVENTIONAL_COMMIT_REGEX='^(feat|fix|docs|style|refactor|test|chore|build|ci|perf|revert)(\([a-zA-Z0-9_.-]+\))?(!)?:\s.*$'

# Check if the commit message matches the regex
if ! [[ $COMMIT_MSG =~ $CONVENTIONAL_COMMIT_REGEX ]]; then
echo "ERRO: A mensagem de commit não segue o formato do Conventional Commits."
echo ""
echo
echo "O formato correto da mensagem de commit é obrigatório:"
echo " <tipo>(<escopo>): <assunto>"
echo ""
echo "Exemplos:"
echo " feat(auth): adicionar funcionalidade de login"
echo " fix(api): resolver problema de timeout"
echo " docs(readme): atualizar instruções de instalação"
echo ""
echo "Tipos válidos são:"
echo " <tipo>(<escopo opcional>): <descrição>"
echo
echo "Os tipos válidos são:"
echo " feat: Uma nova funcionalidade."
echo " fix: Correção de um bug."
echo " docs: Alterações na documentação."
Expand All @@ -35,6 +27,12 @@ if ! [[ $COMMIT_MSG =~ $CONVENTIONAL_COMMIT_REGEX ]]; then
echo " ci: Alterações nos arquivos de configuração de CI ou scripts."
echo " perf: Melhorias de desempenho."
echo " revert: Reverter um commit anterior."
echo
echo "Exemplos:"
echo " feat(auth): adicionar funcionalidade de login"
echo " fix(api)!: resolver problema de timeout"
echo " docs(readme): atualizar instruções de instalação"
echo
exit 1
fi

Expand Down

0 comments on commit 5a28cb9

Please sign in to comment.