Skip to content

Commit

Permalink
✨ Add git msg hook, that ensures each commit as at least one Github I…
Browse files Browse the repository at this point in the history
…ssue associated. Closes #3
  • Loading branch information
D1no committed Mar 14, 2023
1 parent be0b24a commit 9340ed3
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions platform/_tooling/.husky/commit-msg
Original file line number Diff line number Diff line change
@@ -1,10 +1,33 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

## Validating Commit Message for Gitmoji Tag
# Get the commit message
message="$(cat $1)"
requiredPattern="^(🐛|🚨|✏️|✅|🔈|💡|🔇|🎨|👽|⚡️|👌|🔨|📦|🕸|🛰|🍏|🤖|🏁|🍎|🐧|🚑|🔒|🚀|🎉|🔖|⏪|📝|🔀|📄|💬|♿️|📈|🌐|🐳|🗃|💚|👷‍♂️|✨|🚧|💥|💄|🍱|🔥|🚚|🔧|⬆️|⬇️|➕|➖|💩|🍻|🖐|🔺|🔻) .*$"
if ! [[ $message =~ $requiredPattern ]];

## Validate Commit Message for GitHub Issue Number
# POSIX Regex:
# Have a space followed by a hash, digits and a space or end of line
githubIssuePattern=" #[0-9]+($| )"
if ! [[ $message =~ $githubIssuePattern ]];
then
echo "-"
echo "=== Error: Commit message has no associated Github Issue ==="
echo ""
echo "Your commit message was:"
echo $message
echo ""
echo "--"
echo "You need to reference at least one Github Issue. Like: #123"
echo "The first mentioned issue should be the primary ticket."
echo ""
echo "This message was generated from the following script: platform/_tooling/.husky/commit-msg"
echo "-"
exit 1
fi

## Validating Commit Message for Gitmoji Intention Tag
gitmorjiIntentionPattern="^(🐛|🚨|✏️|✅|🔈|💡|🔇|🎨|👽|⚡️|👌|🔨|📦|🕸|🛰|🍏|🤖|🏁|🍎|🐧|🚑|🔒|🚀|🎉|🔖|⏪|📝|🔀|📄|💬|♿️|📈|🌐|🐳|🗃|💚|👷‍♂️|✨|🚧|💥|💄|🍱|🔥|🚚|🔧|⬆️|⬇️|➕|➖|💩|🍻|🖐|🔺|🔻) .*$"
if ! [[ $message =~ $gitmorjiIntentionPattern ]];
then
echo "-"
echo "=== Error: Commit message has no gitmoji tag(s) ==="
Expand Down

0 comments on commit 9340ed3

Please sign in to comment.