Skip to content

Instantly share code, notes, and snippets.

@mauricesvay
Forked from marchelbling/README.md
Created July 9, 2014 09:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mauricesvay/5c718d97c94a35eb9b9d to your computer and use it in GitHub Desktop.
Save mauricesvay/5c718d97c94a35eb9b9d to your computer and use it in GitHub Desktop.
#!/bin/bash
# update hooks; note that this hook will still execute its current version and not
# the updated one
#git pull --rebase &>/dev/null
branch_name=$( git rev-parse --abbrev-ref HEAD )
is_special_branch=$( echo "${branch_name}" | grep -i "^\(hotfix\|develop\|master\|HEAD\)" )
if [ ! "${is_special_branch}" ]
then
suffix=$( echo "${branch_name}" | grep -e "_[0-9]*$" )
if [ ! "${suffix}" ]
then
echo "Bad branch name: should be (feature/bug/chore/)detail_xxxx."
echo "Please use 'git branch -m "${branch_name}" "${branch_name}"_xxxxx"
exit 1
fi
fi
#!/bin/bash
function get_story_id() {
branch_name=$( git rev-parse --abbrev-ref HEAD )
is_special_branch=$( echo "${branch_name}" | grep -i "^\(hotfix\|develop\|master\|HEAD\)" )
suffix=$( echo "${branch_name}" | grep -e "_[0-9]*$" )
# see http://stackoverflow.com/questions/3162385/how-to-split-a-string-in-shell-and-get-the-last-field
story_id=$( echo $branch_name | rev | cut -d'_' -f1 | rev )
if [ "${is_special_branch}" ] && [ ! "${suffix}" ];
then
story_id=""
fi
echo "${story_id}"
}
function get_story_state() {
# see http://stackoverflow.com/questions/3162385/how-to-split-a-string-in-shell-and-get-the-last-field
for state in "Fix" "Finish" "Deliver";
do
state_count=$( echo "$commit_msg" | grep -c -i "^+$state" )
if [ $state_count -gt 0 ];
then
# return state
if [ $state == "Deliver" ];
then
echo "Delivers "
else
echo "${state}es "
fi
break
fi
done
}
function format_commit_msg() {
# strip story state
if [ $story_state ]; then commit_msg="$( echo "$commit_msg" | cut -d' ' -f2- )"; fi
# uppercase first letter
commit_msg="$(tr '[:lower:]' '[:upper:]' <<< ${commit_msg:0:1})${commit_msg:1}"
echo -e "[${story_state}#${story_id}] \n\n${commit_msg}"
}
commit_msg=$( cat $1 )
story_id=$( get_story_id )
if [ "${story_id}" ]
then
story_state=$( get_story_state )
if [ $( echo "${commit_msg}" | grep -F -c "#${story_id}" ) == 0 ];
then
message=$( format_commit_msg "$commit_msg" "$story_id" "$story_state" )
echo "$message" > $1
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment