Skip to content

Instantly share code, notes, and snippets.

@icetan
Created May 14, 2020 08:26
Show Gist options
  • Save icetan/296545aca4de64a551114aa85bcc5b5b to your computer and use it in GitHub Desktop.
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
#!/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