Created
December 12, 2022 18:50
-
-
Save drobinson/5ab1b6e21295129f093bdf8e771a3326 to your computer and use it in GitHub Desktop.
Prepend commit message with Jira ticket number from the current branch
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 | |
# Put this file in .git/hooks/ to prepend all commit messages with the | |
# Jira ticket number found in the current branch name | |
# modified from https://community.atlassian.com/t5/Bitbucket-questions/automatically-append-JIRA-issue-ID-into-commit-message/qaq-p/605991#M24736 | |
# get current branch | |
branchName=`git rev-parse --abbrev-ref HEAD` | |
# search jira issue id in a pattern such a "feature/ABC-123-description" | |
jiraId=$(echo $branchName | sed -nr 's,[a-z]+/([A-Z]+-[0-9]+)-.+,\1,p') | |
# only prepare commit message if pattern matched and jiraId was found | |
if [[ ! -z $jiraId ]]; then | |
# $1 is the name of the file containing the commit message | |
sed -i.bak -e "s/^/\[$jiraId\] /" $1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment