Last active
September 3, 2024 06:13
-
-
Save raduchiriac/36b6269bebb75cfac7371acb1459fdcc to your computer and use it in GitHub Desktop.
Hook: Prepend Jira ticket ID to the git 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 | |
# Get the current branch name | |
current_branch=`git rev-parse --abbrev-ref HEAD` | |
# Search Jira ID in a pattern such a "feature/ABCD-123-my-feature" | |
id=$(echo $current_branch | sed -nE 's,[a-z]+/([A-Z]+-[0-9]+)-.+,\1,p') | |
# only prepare commit message if pattern matched and jiraId was found | |
if [[ ! -z $id ]]; then | |
# $1 is the name of the file containing the commit message | |
# Prepend "ABCD-123: " | |
sed -i.bak -E "1s/^/${id}: /" $1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
add this to your
./.git/hooks/
folder