-
-
Notifications
You must be signed in to change notification settings - Fork 16
feat: update cchk output with more explicit error messages #383
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
23ac625
1aa9808
25b2b02
bdaa3fb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,11 +14,118 @@ Our development branch is `main`. When submitting pull requests, please adhere t | |
|
|
||
| By contributing any code or documentation to this repository (by raising pull requests or otherwise), you explicitly agree to the [License Agreement](https://github.com/commit-check/commit-check/blob/main/LICENSE). | ||
|
|
||
| We appreciate your contributions to make Commit Check even better! | ||
| ## Architecture | ||
|
|
||
| ### Overview | ||
|
|
||
| Commit-check validates Git commit metadata using a pipeline of configurable validators. The key flow is: | ||
|
|
||
| ``` | ||
| CLI args / Env vars / TOML file | ||
| │ | ||
| ▼ | ||
| ConfigMerger ← Merges all config sources (priority: CLI > Env > TOML > Defaults) | ||
| │ | ||
| ▼ | ||
| RuleBuilder ← Builds ValidationRule objects from merged config + rules catalog | ||
| │ | ||
| ▼ | ||
| ValidationEngine ← Iterates over rules, picks the right validator for each | ||
| │ | ||
| ▼ | ||
| BaseValidator subclasses ← Each validator performs one focused check | ||
| │ | ||
| ▼ | ||
| Exit code 0/1 | ||
| ``` | ||
|
|
||
| ### Module responsibilities | ||
|
|
||
| ``` | ||
| commit_check/ | ||
| ├── __init__.py # Package constants: DEFAULT_COMMIT_TYPES, DEFAULT_BRANCH_TYPES, DEFAULT_BOOLEAN_RULES | ||
| ├── main.py # CLI entry point, argument parsing, StdinReader | ||
| ├── config.py # TOML file loading (uses tomllib on Python 3.11+, tomli on older) | ||
| ├── config_merger.py # ConfigMerger: merges CLI → Env → TOML → Defaults | ||
| ├── rule_builder.py # RuleBuilder: creates ValidationRule objects from config + catalog | ||
|
Comment on lines
+49
to
+50
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Correct config merge-order wording and make TOML discovery order explicit. Line 49 currently implies merge is performed from CLI down to defaults, but implementation merges in the opposite direction and only priority is CLI highest. Also, Line 80 should explicitly enumerate the TOML discovery order to avoid ambiguity. Proposed wording update-├── config_merger.py # ConfigMerger: merges CLI → Env → TOML → Defaults
+├── config_merger.py # ConfigMerger: merges Defaults → TOML → Env → CLI (effective priority: CLI > Env > TOML > Defaults)
@@
-| 3 | TOML config files | `cchk.toml`, `.github/cchk.toml`, etc. |
+| 3 | TOML config files | `--config` path, then `cchk.toml`, `commit-check.toml`, `.github/cchk.toml`, `.github/commit-check.toml` |Based on learnings: "Define TOML configuration discovery order: --config argument, cchk.toml, commit-check.toml, .github/cchk.toml, .github/commit-check.toml". Also applies to: 80-81 🤖 Prompt for AI Agents |
||
| ├── rules_catalog.py # Catalog of all rules (COMMIT_RULES, BRANCH_RULES) | ||
| ├── engine.py # ValidationEngine, BaseValidator ABC, ValidationContext, ValidationResult | ||
| ├── imperatives.py # ~258 English imperative verbs for subject validation | ||
| └── util.py # Git operations, output formatting (_print_failure) | ||
| ``` | ||
|
|
||
| ## Development | ||
| ### Validator class hierarchy | ||
|
|
||
| ### Debug commit-check pre-commit hook | ||
| ``` | ||
| BaseValidator (ABC) | ||
| ├── CommitMessageValidator # Full message: conventional commits format | ||
| ├── SubjectValidator (ABC) | ||
| │ ├── SubjectCapitalizationValidator # First letter must be uppercase | ||
| │ ├── SubjectImperativeValidator # Subject must start with imperative verb | ||
| │ └── SubjectLengthValidator # Subject length min/max | ||
| ├── AuthorValidator # Author name and email format | ||
| ├── BranchValidator # Branch naming conventions | ||
| ├── MergeBaseValidator # Merge base / rebase target | ||
| ├── SignoffValidator # Signed-off-by trailer presence | ||
| ├── BodyValidator # Commit body presence | ||
| └── CommitTypeValidator # Handles merge/revert/fixup/wip/empty commits | ||
| ``` | ||
|
|
||
| ### Configuration priority cascade | ||
|
|
||
| | Priority | Source | Example | | ||
| |----------|--------|---------| | ||
| | 1 (highest) | CLI arguments | `--subject-max-length=72` | | ||
| | 2 | Environment variables | `CCHK_SUBJECT_MAX_LENGTH=72` | | ||
| | 3 | TOML config files | `cchk.toml`, `.github/cchk.toml`, etc. | | ||
| | 4 (lowest) | Built-in defaults | defined in `commit_check/__init__.py` | | ||
|
|
||
| ## Development setup | ||
|
|
||
| ### Prerequisites | ||
|
|
||
| - Python 3.9 or newer | ||
| - `nox` for running build sessions: `pip install nox` | ||
|
|
||
| ### Install in development mode | ||
|
|
||
| ```bash | ||
| git clone https://github.com/commit-check/commit-check.git | ||
| cd commit-check | ||
| pip install -e ".[test]" | ||
| ``` | ||
|
|
||
| ### Run tests | ||
|
|
||
| ```bash | ||
| # Fastest: run pytest directly | ||
| pytest tests/ -v | ||
|
|
||
| # With coverage report | ||
| nox -s coverage | ||
| ``` | ||
|
|
||
| ### Lint and format | ||
|
|
||
| ```bash | ||
| # Run all pre-commit hooks (ruff, mypy, codespell, etc.) | ||
| nox -s lint | ||
|
|
||
| # Or install hooks for automatic checks on every commit | ||
| pre-commit install | ||
| ``` | ||
|
|
||
| ### Build documentation | ||
|
|
||
| ```bash | ||
| # One-time build | ||
| nox -s docs | ||
|
|
||
| # Live preview with auto-reload | ||
| nox -s docs-live | ||
| ``` | ||
|
|
||
| ### Test the pre-commit hook locally | ||
|
|
||
| ```bash | ||
| pre-commit try-repo ./../commit-check/ check-message --verbose --hook-stage commit-msg --commit-msg-filename .git/COMMIT_EDITMSG | ||
|
shenxianpeng marked this conversation as resolved.
|
||
|
|
@@ -32,7 +139,7 @@ pip install -e ./../commit-check/ | |
| commit-check -m | ||
| ``` | ||
|
|
||
| ### Test commit-check pre-commit hook on GitHub | ||
| ## Test commit-check pre-commit hook on GitHub | ||
|
|
||
| ```yaml | ||
| - repo: https://github.com/commit-check/commit-check | ||
|
|
@@ -42,3 +149,5 @@ commit-check -m | |
| - id: check-branch | ||
| - id: check-author-email | ||
| ``` | ||
|
|
||
| We appreciate your contributions to make Commit Check even better! | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -110,11 +110,16 @@ def _build_conventional_commit_rule( | |
| allowed_types = self._get_allowed_commit_types() | ||
| regex = self._build_conventional_commit_regex(allowed_types) | ||
|
|
||
| types_str = ", ".join(allowed_types) | ||
| suggest = ( | ||
| f"Use <type>(<scope>): <description>, where <type> is one of: {types_str}" | ||
| ) | ||
|
Comment on lines
+113
to
+116
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Guard against empty If config provides an empty list, Line 115 renders Proposed fix allowed_types = self._get_allowed_commit_types()
+ if not allowed_types:
+ allowed_types = DEFAULT_COMMIT_TYPES
regex = self._build_conventional_commit_regex(allowed_types)
types_str = ", ".join(allowed_types)🤖 Prompt for AI Agents
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Make sense, apply the change @coderabbitai
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
🧠 Learnings usedFailed to handle agent chat message. Please try again.
Comment on lines
110
to
+116
|
||
|
|
||
| return ValidationRule( | ||
| check=catalog_entry.check, | ||
| regex=regex, | ||
| error=catalog_entry.error, | ||
| suggest=catalog_entry.suggest, | ||
| suggest=suggest, | ||
| allowed=allowed_types, | ||
|
shenxianpeng marked this conversation as resolved.
|
||
| ) | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.