This is an implementation for Git Hooks made with Python.
IMPORTANT: To use the scripts it is necessary to have a version of Python 3 installed on your machine.
The files prepare-commit-msg and pre-push (for more details about it, check the git hooks documentation) were modified to use Python.
For each commit the script is called. Basically there is a verification if the commit message is in the defined patterns. We set our patterns as:
- Needs to initiate with feat, chore, test or bug
- Needs to reference, at the end of the message, an open issue and marked with a "doing" label, like this: "(#4)"
Some examples:
git commit -m "feat: implements delete user function (#6)"
git commit -m "test: tests user class (#16)"
git commit -m "bug: fix the insert task bug (#22)"
Simple. Like. That. 😁
But, you can also define you own patterns, for sure. All you need to do is change the line 36:
regex = '^(feat|hotfix|chore|test):.* \(#[0-9]+\)$'
But, keep in mind that the rest of the code depends on the patterns.
Before each push, the script makes some comments on the issue of each commit involved in the operation.
For each commit, a comment with author's name, date and time, changed files and the description of the commit is made in the correspondig issue.
Be like:
And, for each push, a comment with author's name, date and time and number of commits.
Be like:
First of all you need to create a github personal acces token to use it. Place it in the variables inside the scripts:
USERNAME = 'vitumenezes'
TOKEN = 'Token 4Tby&8202&89#rfwtInNSUUnby&82'
⚠️ Need to be like this: 'Token your_access_token'.
Then, just copy the python script to corresponding script inside .git/hooks/
where the example files that git offers are usually located.
⚠️ NOTE: remove the file extension for the script to work. Your file must be likeprepare-commit-msg
and notprepare-commit-msg.py
orprepare-commit-msg.example
.
- Make a fork of this repo;
- Create a branch with your feature:
git checkout -b my-feature
; - Commit your changes:
git commit -m 'feat: my new feature'
; - Push your new branch:
git push origin my-feature
.
NOTE: as you can see, i didn't recommend the patterns with git hooks, it's up to you. If you want to use it, it's great for training 😃
This project is under MIT license. See the file LICENSE for more information.