Created
April 19, 2017 13:39
-
-
Save pavelpower/38a1079cf557b224d5e70b2d5128a116 to your computer and use it in GitHub Desktop.
commit-msg for JIRA
This file contains 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 | |
BRANCH_NAME=$(git branch | grep '*' | sed 's/* //') | |
if [ $BRANCH_NAME != '(no branch)' ] | |
then | |
# создаем временный файл | |
tempname="ticket-id-XXXX"; | |
tempfile=`mktemp $tempname`; | |
# выделяем из имени бранча номер тикета. Бранч всегда называется по шаблону Номер_Краткое_Описание | |
# например 1364_restore_xterm_title или 1364-restore-xterm-title | |
ticket=`git branch|grep '* '| sed -E 's/^([^\/]*\/)([A-Z]+-[0-9]+).*/\2/'`; | |
# берем сообщение комита | |
message=`cat $1`; | |
# если это первый коммит в бранче то вначале описания к коммиту добавляем [#Номер] | |
if [[ $ticket =~ ^[0-9]+$ ]]; then | |
# сливаем во временный файл номер и текст коммита | |
echo "[#$ticket] $message" >> "$tempfile"; | |
# переписываем файл коммита временныйм файлом | |
mv "$tempfile" "$1" | |
else | |
rm $tempfile | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment