Skip to content

Commit

Permalink
chore: Validation script for git commit message conventions (#355)
Browse files Browse the repository at this point in the history
* chore: Validation script for git commit message conventions

Signed-off-by: Darren Murray <[email protected]>
  • Loading branch information
dmurray-lacework authored Apr 1, 2021
1 parent cb55505 commit 7fe9678
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,6 @@ endif
ifeq (, $(shell which gox))
go get github.com/mitchellh/gox
endif

git-env:
scripts/git_env.sh
23 changes: 23 additions & 0 deletions scripts/git_env.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

#!/bin/bash
#
# Name:: git_env.sh
# Description:: Use this script to configure local git env
# Author:: Darren Murray (<[email protected]>)
#

readonly commit_hook=scripts/githooks/commit-msg
readonly hooks_path=scripts/githooks/
readonly project_name=go-sdk

prepare_git_env(){
chmod +x $commit_hook
log "Setting git-hooks path to $hooks_path"
git config core.hooksPath $hooks_path
}

log() {
echo "--> ${project_name}: $1"
}

prepare_git_env
26 changes: 26 additions & 0 deletions scripts/githooks/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash
readonly project_name=go-sdk
readonly commit_tags="feat(:|\(.*\):)|fix(:|\(.*\):)|style(:|\(.*\):)|refactor(:|\(.*\):)\|test(:|\(.*\):)\|docs(:|\(.*\):)\|chore(:|\(.*\):)\|build(:|\(.*\):)\|ci(:|\(.*\):)\|perf(:|\(.*\):)\|metric(:|\(.*\):)\|misc(:|\(.*\):)"
readonly commit_message=`cat $1`
readonly blah="Please enter the commit message for your changes"

validate_commit_message(){
if ! [[ $commit_message =~ $commit_tags ]]; then
invalid_message
exit 1
fi
log "Commit message is valid"
}

invalid_message(){
log "Invalid commit message"
log "Message must contain one of feat: | fix: | style: | refactor: | test: | docs: | chore: | build: | ci: | perf: | metric: | misc:
Or with scope in parenthesis eg. feat(cli): Add new feature"
}

log() {
echo "--> ${project_name}: $1"
}

validate_commit_message

0 comments on commit 7fe9678

Please sign in to comment.