Created
May 14, 2020 08:26
-
-
Save icetan/296545aca4de64a551114aa85bcc5b5b to your computer and use it in GitHub Desktop.
GIT commit message hook to add story ID from branch name, support for JIRA and ClubHouse
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 | |
file="$1" | |
branch=$(git rev-parse --abbrev-ref HEAD 2>&-) | |
check() { | |
local cmd=$1 | |
local id=$($cmd <<<"$branch") | |
if [[ ! $(head -n1 "$file" | $cmd) ]]; then | |
echo $id | |
fi | |
} | |
clubhouse() { grep -Eo '\bch[0-9]{1,}\b'; } | |
jira() { grep -Eo '^[A-Z]{1,}-[0-9]{1,}\b'; } | |
if [[ ${chid=$(check clubhouse)} ]]; then | |
sed -i"" "1s/\$/ [$chid]/" "$file" | |
elif [[ ${jid=$(check jira)} ]]; then | |
sed -i"" "1s/^/$jid /" "$file" | |
fi | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment