-
-
Save Rahul91/4049ae946192059fa686c9b1aa306b61 to your computer and use it in GitHub Desktop.
commit-msg hook to detect commit message length.
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/python3 | |
import sys | |
class bcolors: | |
OKCYAN = '\033[96m' | |
WARNING = '\033[93m' | |
FAIL = '\033[91m' | |
ENDC = '\033[0m' | |
def main(): | |
messageFile = sys.argv[1] | |
try: | |
file = open(messageFile, 'r') | |
message = file.read() | |
finally: | |
file.close() | |
is_valid = len(message.split(" ")) > 5 | |
if not is_valid: | |
print(f"{bcolors.WARNING}WARNING: Commit message less than 5 words.{bcolors.ENDC}") | |
print(f"{bcolors.OKCYAN}Try commiting again with verbose commit message{bcolors.ENDC}\n") | |
print(f"{bcolors.FAIL}Error: Commit Failed.{bcolors.ENDC}") | |
sys.exit(0 if is_valid else 1) | |
if __name__ == "__main__": | |
main() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment