Skip to content

Instantly share code, notes, and snippets.

@raduchiriac
Last active April 17, 2024 13:43
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 6 You must be signed in to fork a gist
  • Save raduchiriac/36b6269bebb75cfac7371acb1459fdcc to your computer and use it in GitHub Desktop.
Save raduchiriac/36b6269bebb75cfac7371acb1459fdcc to your computer and use it in GitHub Desktop.
Hook: Prepend Jira ticket ID to the git commit message
#!/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
@raduchiriac
Copy link
Author

add this to your ./.git/hooks/ folder

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment