Skip to content

Instantly share code, notes, and snippets.

@yoniamir
Last active April 2, 2023 10:35
Show Gist options
  • Save yoniamir/3870686d60315cef0296b81f8d8175a0 to your computer and use it in GitHub Desktop.
Save yoniamir/3870686d60315cef0296b81f8d8175a0 to your computer and use it in GitHub Desktop.
Set a git hook that appends the Jira ticket name into the commit message
#!/bin/sh
# Get the current branch name
branch_name=$(git symbolic-ref --short HEAD)
# Extract the ticket number from the branch name using a regex
ticket_number=$(echo $branch_name | grep -o -E '[A-Za-z]+-[0-9]+')
# Check if a ticket number was found
if [ -n "$ticket_number" ]; then
# Read the original commit message from the provided file
original_msg=$(cat "$1")
# Append the ticket number to the commit message
new_msg="$ticket_number $original_msg"
# Save the new commit message back to the provided file
echo "$new_msg" > "$1"
fi
curl https://gist.githubusercontent.com/yoniamir/3870686d60315cef0296b81f8d8175a0/raw/6545b1ce86d00ab4419caa583cb32952aa466ef9/commit-msg -o .git/hooks/commit-msg
chmod +x .git/hooks/commit-msg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment