DEV Community

Discussion on: Write better PR's with this template πŸ“„

Collapse
 
cookiemonsterdev profile image
Mykhailo Toporkov πŸ‡ΊπŸ‡¦

Have you considered using conventional commits system? You can ease enforce this just by set up pre-commit hook like husky with sth like:

#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

red=$(tput setaf 1) # ANSI escape code for red color
reset=$(tput sgr0)  # ANSI escape code to reset color

#Commit message check

commit_msg=$(git log -1 --pretty=%B)

if ! echo "$commit_msg" | grep -qE "^(feat|fix|chore|docs|test|style|refactor|perf|build|ci|revert)(\(.+?\))?:? .{1,}$
"; then
    echo "${red}Error${reset}: Invalid commit format, try: feat(feature): description." >&2
    exit 1
fi

if [ ${#commit_msg} -gt 88 ]; then
    echo "${red}Error${reset}: Invalid commit length. Your commit message is too long." >&2
    exit 1
fi
Enter fullscreen mode Exit fullscreen mode
Collapse
 
nicolasmontielf profile image
Nico Montiel

In a previous job, we used to use conventional commits, and it's an amazing practice to do so.
Thanks for sharing this script, I'm sure you'll make someone's life super easy with this πŸ˜„

Some comments have been hidden by the post's author - find out more