Skip to content

Instantly share code, notes, and snippets.

View kilab's full-sized avatar

Paweł Balicki kilab

View GitHub Profile
@kilab
kilab / commit-msg
Created October 26, 2019 10:11
Conventional Commits validator to commit-msg git hook. Pure bash script without any dependencies.
#!/usr/bin/env bash
# Variables
COMMIT_MSG=$(cat "${1:?Missing commit message file}")
REGEX="([a-z]+)(\([a-z ]+\))?:([\w ]+)"
VALID_TYPES=('fix' 'feat' 'chore' 'docs' 'style' 'refctor' 'perf' 'ci' 'test')
# Validation
if ! [[ $COMMIT_MSG =~ $REGEX ]] || [[ $COMMIT_MSG =~ [A-Z] ]]; then
printf "ERR: Invalid commit message structure.\n"