Last active
August 16, 2017 16:50
-
-
Save mewm/d63e3d9d69422b2b8ae93648b6ca0568 to your computer and use it in GitHub Desktop.
Git hook to extract ticket id by regex, to prefix the message with the ticket id when staging with a 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/sh | |
# Default regex for clubhouse.io tickets | |
DEFAULT_TICKET_REGEX="ch\d\+" | |
: ${TICKET_ID_REGEX:=$DEFAULT_TICKET_REGEX} | |
# Example | |
# Branch: ch1623/global-sitemap-urls-are-relative | |
# Message: Fixed that shit | |
# Result commit message: "ch1623: Fixed that shit" | |
prefixExtractedTicketIdToMessage() { | |
branch_name=$(git branch | grep '*' | sed 's/* //') | |
ticket_id=$(echo $branch_name | grep -io "$TICKET_ID_REGEX" ) | |
if [ $ticket_id ]; then | |
echo "$ticket_id: $2" > $1 | |
fi | |
} | |
case "$2,$3" in | |
# Matches Typical git comm | |
message,) | |
prefixExtractedTicketIdToMessage $1 $2 | |
;; | |
# Merge commits | |
merge,) | |
;; | |
# Non-merges with no prior messages | |
*) | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment