#!/usr/bin/env python
##
# @author Prahlad Yeri
# @email prahladyeri@yahoo.com
# @title Git hook for enforcing conventional commit spec
#
# @todo Create folder ~/.git-templatesand set that value to init.templatedir git config key globally.
# @todo Copy this script to ~/.git-templates/hooks/ and rename it to commit-msg.
# @todo (Linux): Make the script executable.
import re, sys, os

def main():
	# example:
	# feat(apikey): added the ability to add api key to configuration
	pattern = r'(build|ci|docs|feat|fix|perf|refactor|style|test|chore|revert)(\([\w\-]+\))?:\s.*'
	filename = sys.argv[1]
	ss = open(filename, 'r').read()
	m = re.match(pattern, ss)
	if m == None: raise Exception("conventional commit validation failed")

if __name__ == "__main__":
	main()