Created
June 1, 2020 11:19
-
-
Save yoeunes/7763e95689ad026d209a93a6d89b8dd9 to your computer and use it in GitHub Desktop.
git hook to add Jira or Gitlab issue ID to commit message
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# Automatically adds Jira key to commit message | |
# | |
BRANCH_NAME=$(git symbolic-ref --short HEAD) | |
if [[ $BRANCH_NAME =~ feat/.* ]] || [[ $BRANCH_NAME =~ fix/.* ]]; then | |
BRANCH_ISSUE_ID="${BRANCH_NAME##*/}" | |
BRANCH_IN_COMMIT=$(grep -c "\[#[0-9]*\]" "$1") | |
if ! [[ $BRANCH_IN_COMMIT -eq 1 ]] && ! [[ $(cat "$1") == "$BRANCH_ISSUE_ID"* ]] && ! [ -z "$BRANCH_ISSUE_ID" ]; then | |
echo "[#$BRANCH_ISSUE_ID] $(cat "${1}")" > "$1" | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment