Skip to content

Instantly share code, notes, and snippets.

@mvlabat
Last active April 10, 2017 14:46
Show Gist options
  • Save mvlabat/36b9b0c403b2d27ea37b16fb9512798f to your computer and use it in GitHub Desktop.
Save mvlabat/36b9b0c403b2d27ea37b16fb9512798f to your computer and use it in GitHub Desktop.
Prepend branch task code or "techdebt: " to git commit message
#!/bin/bash
commit_msg=$(<$1)
branch_name=$(git symbolic-ref HEAD)
regex='(\[#[0-9]+\]|techdebt\:) .+'
[[ $commit_msg =~ $regex ]] && exit 0
regex='refs\/heads\/(feature|bugfix|hotfix|techdebt)\/([0-9]+)-.+'
[[ $branch_name =~ $regex ]] && task_code="${BASH_REMATCH[2]}"
echo -e "\033[33mYour commit message doesn't have either commit number ('[#12345] message') or 'techdebt: ' prepended.\033[0m"
echo 'CHOOSE OPTION:'
[ ! -z "$task_code" ] && echo "1 - prepend '[#$task_code] ' to commit message"
echo "2 - prepend 'techdebt: ' to commit message"
echo "<any other input> - save as it is"
echo ''
option=0
read -p "ENTER HERE: " option </dev/tty
case "$option" in
1) [ ! -z "$task_code" ] && echo "[#$task_code] $commit_msg" > "$1" ;;
2) echo "techdebt: $commit_msg" > "$1" ;;
esac
echo ''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment