Skip to content

Instantly share code, notes, and snippets.

View sanG-github's full-sized avatar

Sang Huynh Thanh sanG-github

View GitHub Profile
@sanG-github
sanG-github / Prepend the Ticket Number into the commit message
Created October 24, 2023 08:47
Prepend the Ticket Number into the commit message
#!/bin/bash
FILE=$1
MESSAGE=$(cat $FILE)
TICKET=[$(git rev-parse --abbrev-ref HEAD | grep -Eo '^(\w+/)?(\w+[-_])?[0-9]+' | grep -Eo '(\w+[-])?[0-9]+' | tr "[:lower:]" "[:upper:]")]
if [[ $TICKET == "[]" || "$MESSAGE" == "$TICKET"* ]];then
exit 0;
fi
echo "$TICKET $MESSAGE" > $FILE