Skip to content

Instantly share code, notes, and snippets.

@vladimir-bebeshko
Last active October 13, 2025 13:30
Show Gist options
  • Save vladimir-bebeshko/1dcb3a8b33342306c9baba88a9703656 to your computer and use it in GitHub Desktop.
Save vladimir-bebeshko/1dcb3a8b33342306c9baba88a9703656 to your computer and use it in GitHub Desktop.
Extract JIRA ticket name from the branch name and prepare commit message
#!/bin/bash
#
# Succeed on all merge and rebase messages, as evidenced by MERGE_MSG and SQUASH_MSG existing
[ -f "$GIT_DIR"/MERGE_MSG ] || [ -f "$GIT_DIR"/SQUASH_MSG ] && exit 0
JIRA_TAG_PATTERN="mnlth-[0-9]+"
BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD 2> /dev/null \
| grep -oiE "$JIRA_TAG_PATTERN" \
| tr '[:lower:]' '[:upper:]')
USER_MSG=$(cat $1)
MSG=$(echo $USER_MSG | tr '[:upper:]' '[:lower:]')
if [[ -n "$BRANCH_NAME" && !($MSG =~ $JIRA_TAG_PATTERN) ]]; then
sed -i '' "1s/^/$BRANCH_NAME /g" $1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment