How To Enforce Conventional Commit Messages Using GIT Hooks

git commit -m "added social login feature for authentication using twitter"
git commit -m "feat(authentication): added social login using twitter"
> git log --oneline
61c8ca9 (HEAD -> master) fix: navbar not responsive on mobile
479c48b test: prepared test cases for user authentication
a992020 chore: moved to semantic versioning
b818120 fix: button click even handler firing twice
c6e9a97 fix: login page css
dfdc715 feat(authentication): added social login using twitter
Photo by Chris Ried on Unsplash
logs
hooks
objects
refs
git init .
#!/usr/bin/env python
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()
> git commit -m "added a new feature for xyz"
Traceback (most recent call last):
File "C:/Users/prahlad/Documents/scripts/check_commit.py", line 22, in <module>
main()
File "C:/Users/prahlad/Documents/scripts/check_commit.py", line 19, in main
if m == None: raise Exception("conventional commit validation failed")
Exception: conventional commit validation failed
Now test with a valid commit message and it should work!
pip install enforce-git-message

--

--

--

Freelance Programmer and Writer. Educate and solve problems is my mantra. I work on full stack web development and automation projects.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

How to Handle Common Selenium Issues Using Python (Part 1)

Featured image for Selenium WebDriver challenges and solutions

Differences in OOP and Functional Programming

GDDP — Grafana Dashboards Development Process

Product reviews — Improving quality while learning on the job

Multilingual Support Now Available on the Assemble App

Elastic Kubernetes Service

TASK-4:AWS VPC with public, private subnets, internet gateway and NAT gateway

Send Slack Notifications with Jenkins

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Prahlad Yeri

Prahlad Yeri

Freelance Programmer and Writer. Educate and solve problems is my mantra. I work on full stack web development and automation projects.

More from Medium

Git (Global Information Tracker)

How to run Oracle SQL Developer on M1

Time. GitHub History. Commit From 2000. How I Submitted Into Past.

Easy Error Handling in aiohttp with aiohttp-catcher