Last active
April 13, 2020 23:11
-
-
Save buddharage/96a2c45559652824f28c23d4c5dcc175 to your computer and use it in GitHub Desktop.
Prepend Commit Message with Jira Ticket ID
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 | |
# Get the current branch name and check if it is excluded | |
BRANCH_NAME=$(git symbolic-ref --short HEAD) | |
# Trim it down to get the parts we're interested in | |
TRIMMED="$(echo "$BRANCH_NAME" | grep -Eo "[A-Z]{3,10}-[0-9]+")" | |
# See if the ticket prepend is already in the commit message | |
JIRA_ID_IN_MSG="$(grep -Eo "[A-Z]{3,}-[0-9]+\s\|\s" "$1")" | |
# If it isn't excluded, preprend the trimmed branch identifier to the given message | |
# Only prepend if | |
# * There is a branch name | |
# * There is a Jira ID in the branch name | |
# * There is NOT a Jira ID already prepended to the message | |
if [ -n "$BRANCH_NAME" ] && [ -n "$TRIMMED" ] && [ -z "$JIRA_ID_IN_MSG" ]; then | |
echo "Prepending commit message..." | |
sed -i.bak -e "1s/^/$TRIMMED | /" "$1" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment