Skip to content

Instantly share code, notes, and snippets.

@mewm
Last active August 16, 2017 16:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mewm/d63e3d9d69422b2b8ae93648b6ca0568 to your computer and use it in GitHub Desktop.
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.
#!/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