Created
July 8, 2022 14:57
-
-
Save abalejr/6d3183b4c0acb8bbcc701e1dfe6d6ddb to your computer and use it in GitHub Desktop.
Append Issue Number to Commit Message
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 | |
MESSAGE=$(cat $FILE) | |
TICKET=$(git rev-parse --abbrev-ref HEAD | grep -Eo '^(\w+/)?(\w+[-_])?[0-9]+' | grep -Eo '(\w+[-])?[0-9]+' | tr "[:lower:]" "[:upper:]") | |
if [[ $TICKET == "" || "$MESSAGE" == "$TICKET"* ]];then | |
exit 0; | |
fi | |
echo "$MESSAGE (#$TICKET)" > $FILE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Works by including the issue number in your branch name.
Put it in your project in the
.git/hooks
folderIf you wanna install it by default on any repo you do
git init
on, you can add it to~/.git-templates/hooks
. Just create the folders if they don't exist.Example:
Commits made to a branch called
69420_to_the_moon
will have(#69420)
appended to the message automagically. Yes, there is a space before the opening parenthesis. So if you dogit commit -m "Buy the dip"
, your message will beBuy the dip (#69420)
.GitHub will automatically link your commits to the issue, showing them in the timeline of the issue and you'll be able to hover over the link when looking at the commit history and see a tooltip for the issue.