conventional-commits-check
is a Python pre-commit hook that enforces Conventional Commits rules on your commit messages and automatically adds relevant emojis based on the commit type.
Conventional Commits is a lightweight convention that provides a set of rules for creating an explicit commit history. This pre-commit hook helps ensure your commit messages adhere to the convention and provides additional context with emojis.
Automatic emoji insertion at the beginning of the Commit ๐
{
"feat": "โจ",
"fix": "๐",
"docs": "๐",
"style": "๐",
"refactor": "๐งน",
"perf": "๐",
"test": "๐งช",
"build": "๐๏ธ",
"ci": "๐ท",
"chore": "โป๏ธ",
"revert": "โช",
}
touch commits_check_config.yaml.yaml
NOTE
: Please do not leave it blank if you create it.
To add custom commit types and emojis, update your commits_check_config.yaml
file with the additional_commands and additional_emojis fields. Here's an example:
additional_commands:
database: "^database(\\(.+\\))?:"
design: "^design(\\(.+\\))?:"
additional_emojis:
database: "๐๏ธ"
design: "๐จ"
This is how you can change the emojis of existing commands.
additional_commands:
fix: "^fix(\\(.+\\))?:"
feat: "^feat(\\(.+\\))?:"
additional_emojis:
fix: "๐๏ธ"
feat: "๐จ"
- Checks if commit messages follow the Conventional Commits rules.
- Adds an emoji to the commit message based on the commit type.
- Blocks commits with non-conforming messages.
Follow these steps to add the conventional-commits-check
pre-commit hook to your project:
- In your project's root directory, open the existing
.pre-commit-config.yaml
file (or create one if it doesn't exist) and add the following content:
repos:
- repo: https://github.com/AliYmn/conventional-commits-check
rev: v0.3.0 # Use the latest release version
hooks:
- id: conventional-commits-check
stages: [commit-msg]
args: ["--emoji-disabled"] # Add this argument to disable emojis
- Update the pre-commit hooks in your project:
pre-commit install --hook-type commit-msg -f
- Install the conventional-commits-check package:
pip install -U conventional-commits-check
- You may need to update the pre-commit package;
pre-commit autoupdate
Once the hook is added to your project, it will automatically run every time you create a commit. The hook will check the commit messages according to the Conventional Commits rules and add corresponding emojis. If a commit message does not follow the rules, the commit will be blocked.