Skip to content

Instantly share code, notes, and snippets.

@vladimir-bebeshko
Last active October 13, 2023 19:20
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
JIRA_TAG_PATTERN="mob-[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