Skip to content

Instantly share code, notes, and snippets.

@sujith-es
Forked from raduchiriac/prepare-commit-msg
Created November 24, 2022 12:14
Show Gist options
  • Save sujith-es/98f1ccf609bd8707722ccaecfff4197a to your computer and use it in GitHub Desktop.
Save sujith-es/98f1ccf609bd8707722ccaecfff4197a 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
@sujith-es
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