Created
July 25, 2020 13:15
-
-
Save mobeigi/eafda51ce8db12b63b3660e6800e24ff to your computer and use it in GitHub Desktop.
Git Commit Message Hook for JIRA Issue Keys
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 | |
# The script below adds the branch name automatically to | |
# every one of your commit messages. The regular expression | |
# below searches for JIRA issue key's. The issue key will | |
# be extracted out of your branch name | |
# | |
# A variant of grep support the -P flag for PCRE is required | |
# | |
REGEX_ISSUE_ID="((?!([A-Z0-9a-z]{1,10})-?$)[A-Z]{1}[A-Z0-9]+-\d+)" | |
# Find current branch name | |
BRANCH_NAME=$(git symbolic-ref --short HEAD) | |
if [[ -z "$BRANCH_NAME" ]]; then | |
echo "No branch name... "; exit 1 | |
fi | |
# Extract issue id from branch name | |
ISSUE_ID=$(echo "$BRANCH_NAME" | LC_ALL=en_US.utf8 grep -o -P "$REGEX_ISSUE_ID") | |
# Prepend issue id if it was found | |
if [[ -z "$ISSUE_ID" ]]; then | |
echo $(cat "$1") > "$1" | |
else | |
echo "$ISSUE_ID"': '$(cat "$1") > "$1" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Setup instructions:
https://mobeigi.com/blog/programming/git-commit-message-hook-for-jira-issue-keys/