How aliymn/conventional-commits-check works
Project Overview and Purpose
• The project, “conventional-commits-check”, is a Python package designed to be used as a pre-commit hook. It enforces Conventional Commits rules on commit messages and can optionally prepend emojis based on the commit types.
• The README makes it clear that the core goal is to ensure that commit messages follow a standardized format, enhancing versioning and collaboration.
File Structure
• Key directories and files:
• conventional_commits_check/ – Contains the core logic via main.py and commit_types.py. This directory houses the application’s primary modules.
• test/ – Contains unit tests (e.g., test_main.py) to verify functionality.
• commits_check_config.yaml – External configuration file for customization of commit types and emojis.
• setup.py and requirements.txt – Standard Python packaging files.
• .pre-commit-config.yaml and other pre-commit hooks files – Integration points ensuring that the tool is used as part of a Git commit workflow.
• CI/CD configuration files in .github/workflows/ – Automatically build, test, and deploy package updates.
• The structure signals a standard Python library with testing, configuration, and continuous integration support.
Key Architectural Components
• Pre-commit Integration:
• This component is represented by configuration files (like .pre-commit-config.yaml) that tie Git’s commit-msg hook to invoke the tool.
• The flow starts when a developer attempts to make a commit; the Git hook triggers the “conventional-commits-check” script.
• Core Commit Validator:
• Located inside the conventional_commits_check package (main.py), this module contains the logic to validate commit messages.
• It leverages commit type definitions from commit_types.py to check if a commit message adheres to the Conventional Commits specification.
• Customization Module:
• The commits_check_config.yaml allows end users to define additional commit types and emojis.
• Developers can customize behavior by modifying commit_types.py or the YAML file.
• Testing & CI/CD:
• The test folder is dedicated to unit tests ensuring functionality and robustness.
• Github workflows (in .github/workflows) automatically run tests, enforce code style, and publish the package on PyPI.
Relationships and Data Flow
• A Git commit triggers the pre-commit hook (configured in .pre-commit-config.yaml).
• The hook calls the main logic in conventional_commits_check/main.py.
• main.py uses commit_types.py and the configuration file commits_check_config.yaml to determine what constitutes a valid commit message.
• Depending on settings, the script may transform auto-merge commit messages or prepend emojis.
• Results are either a successful commit (when compliant) or a block with an error message.
Important Architectural Patterns and Technologies
• Modular design: Separation into core validation logic, configurable types, and tests.
• Pre-commit hook integration to enhance Git workflows.
• Standard Python packaging and CI/CD pipelines ensure maintainability and smooth deployments.
• Emphasis on configuration-driven behavior (YAML file for custom commit types/emojis).