Last active
July 18, 2018 18:04
-
-
Save chalasr/e1926e067e8c75d8fcc6 to your computer and use it in GitHub Desktop.
Beautify git commit message by capitalize message's first letter + prepend issue ID from ref.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # original message | |
| base=$(cat $1) | |
| # ticket patterns | |
| patterns=(ticket- issue- bug-) | |
| # current branch name excluding namespace | |
| current_branch=$(git symbolic-ref --short HEAD | cut -d/ -f2-) | |
| # capitalize message's first char | |
| message=`echo ${base:0:1} | tr '[a-z]' '[A-Z]'`${base:1} | |
| # retrieve ticket number from patterns | |
| i=0; | |
| while [ $i -le 2 ]; do | |
| pattern=${patterns[$i]} | |
| if [ "${current_branch#$pattern}" != "$current_branch" ]; then | |
| ticket=${current_branch#$pattern} | |
| fi | |
| ((i++)) | |
| done | |
| # prepend number to commit message | |
| if [ -n "$ticket" ]; then | |
| echo "#$ticket $message" > $1 | |
| else | |
| echo "$message" > $1 | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment