Skip to content

Instantly share code, notes, and snippets.

@aabouzaid
Created September 25, 2020 09:39
Show Gist options
  • Save aabouzaid/20b9d48e150777dcb7833e7b3fe3538b to your computer and use it in GitHub Desktop.
Save aabouzaid/20b9d48e150777dcb7833e7b3fe3538b to your computer and use it in GitHub Desktop.
Add JIRA ticket ID to Git commit message
#!/bin/bash
COMMIT_MSG_FILE=$1
TICKET_ID_PATTERN="INFRA-[0-9]+"
TICKET_ID=$(git symbolic-ref --short HEAD | egrep -o "${TICKET_ID_PATTERN}")
TICKET_MSG_IN_COMMIT=$(grep -c "Related to: ${TICKET_ID}" ${COMMIT_MSG_FILE})
if [[ -n "${TICKET_ID}" && ${TICKET_MSG_IN_COMMIT} -lt 1 ]]; then
echo -e "\nRelated to: ${TICKET_ID}" >> ${COMMIT_MSG_FILE}
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment