Skip to content

Instantly share code, notes, and snippets.

@mahtaran
Last active January 5, 2023 01:19
Show Gist options
  • Save mahtaran/b202b92a26fdd52c78197e7373cb3a91 to your computer and use it in GitHub Desktop.
Save mahtaran/b202b92a26fdd52c78197e7373cb3a91 to your computer and use it in GitHub Desktop.
msg_file="$1"
r_gitmoji_text="(:[a-z0-9_+-]+:)"
# r_gitmoji_unicode="[\u{1f300}-\u{1f5ff}\u{1f900}-\u{1f9ff}\u{1f600}-\u{1f64f}\u{1f680}-\u{1f6ff}\u{2600}-\u{26ff}\u{2700}-\u{27bf}\u{1f1e6}-\u{1f1ff}\u{1f191}-\u{1f251}\u{1f004}\u{1f0cf}\u{1f170}-\u{1f171}\u{1f17e}-\u{1f17f}\u{1f18e}\u{3030}\u{2b50}\u{2b55}\u{2934}-\u{2935}\u{2b05}-\u{2b07}\u{2b1b}-\u{2b1c}\u{3297}\u{3299}\u{303d}\u{00a9}\u{00ae}\u{2122}\u{23f3}\u{24c2}\u{23e9}-\u{23ef}\u{25b6}\u{23f8}-\u{23fa}\u{200d}]"
# unfortunately, the unicode regex is not supported, so we just match any non-whitespace
r_gitmoji_unicode="\S+"
r_gitmoji="(${r_gitmoji_text}|${r_gitmoji_unicode})"
r_subject="([[:graph:]][[:print:]]{0,70}[[:graph:]])"
r_issue="( \(#\d+\))?"
pattern="^${r_gitmoji} ${r_subject}${r_issue}$"
if grep --extended-regexp --quiet "${pattern}" "${msg_file}"; then
exit 0
fi
if test -t 1 && test -n "$(tput colors)"; then
RED='\033[0;31m'
GREEN='\033[0;32m'
BLUE='\033[0;34m'
PURPLE='\033[0;35m'
NC='\033[0m'
fi
echo -e "${RED}ERROR: Invalid commit message${NC}:
${PURPLE}$( cat "${msg_file}" )${NC}
"
echo -e "
Your commit message does ${RED}not${NC} follow our ${PURPLE}commit naming guidelines${NC}: ${BLUE}https://github.com/amuzil/.github/blob/main/.github/contributing.md#commits${NC}
Commit messages should start with a ${GREEN}gitmoji${NC} followed by a space, followed by the commit message.
If the commit is related to an issue, the issue number should be added in parentheses at the end of the commit message.
Example commit message:
${GREEN}✨ Add new feature (#42)${NC}
"
exit 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment