Created
July 21, 2022 04:02
-
-
Save sophea/660d115ac500f4cab4a062e5171fd5cf to your computer and use it in GitHub Desktop.
custom commit-msg
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
#!/usr/bin/env bash | |
# | |
# @author : Mak Sophea | |
# @version : 1.0# | |
# Create a regex for a conventional commit. | |
commit_types="(build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test|wip)" | |
convetional_commit_regex="^${commit_types}(\([a-z \-]+\))?!?: .+$" | |
# Get the commit message (the parameter we're given is just the path to the | |
# temporary file which holds the message). | |
commit_message=$(cat "$1") | |
# Check the message, if we match, all good baby. | |
if [[ "$commit_message" =~ $convetional_commit_regex ]]; then | |
echo -e "\e[32mCommit message meets Conventional Commit standards...\e[0m" | |
exit 0 | |
fi | |
# Uh-oh, this is not a conventional commit, show an example and link to the spec. | |
echo -e "\e[31mThe commit message does not meet the Conventional Commit standard\e[0m" | |
echo "An example of a valid message is: " | |
echo " feat(login): add the 'remember me' button" | |
echo "More details at: https://www.conventionalcommits.org/en/v1.0.0/#summary" | |
echo "***********************************************************************" | |
echo "Here are the list of message type : ${commit_types}" | |
echo " <type>: <subject> max 50char ex :- fix: invalid request for login api" | |
echo " <type(<scope>):> <subject> (Max 50 char) - <scope> is option ex: - fix(user): email address is empty on profile api" | |
echo "***********************************************************************" | |
exit 1 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment