This is a hook that adds the ticket number to the commit message, if it can be infered by the branch name.
(ex. branch name bugfix/5234-fix-a-thing
would result in #5234
for the github version or [t: 5234]
for the codebase version.
Last active
December 12, 2018 10:49
-
-
Save Geekfish/ac19370af3fe06425e899b30e4eb3e7d to your computer and use it in GitHub Desktop.
Ticket in commit msg (Github and CodebaseHQ versions)
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
[core] | |
... | |
hooksPath = /path/to/hooks/ |
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/sh | |
# CodebaseHQ version | |
LF=$'\\\x0A' | |
BRANCH_NAME=$(git symbolic-ref --short HEAD) | |
if [[ $BRANCH_NAME =~ .*\/[0-9]* ]]; then | |
NUMBER=$(echo $BRANCH_NAME | sed 's/[^0-9]*//g') | |
MESSAGE="\[t: $NUMBER\]" | |
MESSAGE_IN_COMMIT=$(grep -c "$MESSAGE" $1) | |
if [ $NUMBER ] && [ $MESSAGE_IN_COMMIT -lt 1 ]; then | |
sed -i.back "1s/$/$LF$LF$MESSAGE$LF/" "$1" | |
fi | |
fi |
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/sh | |
# Github version | |
LF=$'\\\x0A' | |
BRANCH_NAME=$(git symbolic-ref --short HEAD) | |
if [[ $BRANCH_NAME =~ .*\/[0-9]* ]]; then | |
NUMBER=$(echo $BRANCH_NAME | sed 's/[^0-9]*//g') | |
MESSAGE="#$NUMBER" | |
MESSAGE_IN_COMMIT=$(grep -c "$MESSAGE" $1) | |
if [ $NUMBER ] && [ $MESSAGE_IN_COMMIT -lt 1 ]; then | |
sed -i.back "1s/$/$LF$LF$MESSAGE$LF/" "$1" | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment