Skip to content

Instantly share code, notes, and snippets.

@hamzaPixl
Last active December 4, 2018 10:59
Show Gist options
  • Select an option

  • Save hamzaPixl/34817ca39aeb140b44070a728613310e to your computer and use it in GitHub Desktop.

Select an option

Save hamzaPixl/34817ca39aeb140b44070a728613310e to your computer and use it in GitHub Desktop.
Put the tag present in the name of the branch in your commit message.
{
"hooks": {
"prepare-commit-msg": "hooks/prepare-commit-msg.sh ${HUSKY_GIT_PARAMS}"
}
}
#!/bin/bash
BRANCHES_TO_SKIP=(master development production staging test)
BRANCH=$(git symbolic-ref --short HEAD)
COMMIT_MESSAGE=$1
echo "Branch $(cat $BRANCH)"
echo "Changing the commit message:"
echo "$(cat $COMMIT_MESSAGE)"
BRANCH_EXCLUDED=$(printf "%s\n" "${BRANCHES_TO_SKIP[@]}" | grep -c "^$BRANCH$")
if ! [[ $BRANCH_EXCLUDED -eq 1 ]]; then
TICKET=$(echo $BRANCH | grep -o -E '[A-Za-z]+-[0-9]+' | head -1)
if [ ! -z $TICKET ]; then
printf "[$TICKET] $(cat $COMMIT_MESSAGE)" > $COMMIT_MESSAGE
else
printf "[TAG] $(cat $COMMIT_MESSAGE)" > $COMMIT_MESSAGE
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment