| Crates.io | forgejo-commit-path-rules |
| lib.rs | forgejo-commit-path-rules |
| version | 0.2.3 |
| created_at | 2025-03-09 08:22:58.249227+00 |
| updated_at | 2025-03-22 10:47:16.462494+00 |
| description | Enforce consistency between commit messages and file changes in your repository |
| homepage | |
| repository | https://codeberg.org/kemitix/forgejo-commit-path-rules |
| max_upload_size | |
| id | 1585273 |
| size | 182,585 |
A tool to enforce consistency between commit messages and file changes in your repository.
This tool validates that commits follow specific patterns and include changes to required files or directories. It's particularly useful for ensuring that:
any or all matching strategies for file pathscargo install forgejo-commit-path-rules
forgejo-commit-path-rules --workspace /path/to/your/repo --no-colour
Options:
--workspace: Root directory of the project to be scanned (optional, defaults to current directory)--verbose: Enable verbose logging for detailed output--no-color: Disabled colours in logsIf no --workspace argument is provided, the tool will use the current working directory as the workspace.
name: Validate Commit Path Rules
on:
pull_request:
branches: [ main ]
push:
branches: [ next ]
jobs:
validate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Run forgejo-commit-path-rules
uses: kemitix/commit-path-rules@v0.1.4
with:
args: --verbose # Enable verbose logging in actions (optional)
If the action is invoked for other events than push or pull-request, then it will return a pass result.
You should be able to use this with GitHub and/or GitLab, although it hasn't been tested.
forgejo-commit-path-rules looks for the following environment variables:
GITHUB_WORKSPACE: The absolute path to the repository workspace directoryGITHUB_EVENT_NAME: The name of the event that triggered the workflow (e.g., "push", "pull_request")GITHUB_BASE_REF: The target branch of a pull request (used for pull request events)GITHUB_HEAD_REF: The source branch of a pull request (used for pull request events)GITHUB_SHA: The sha of the commit being pushed (used for puhs events)validate_commits:
stage: test
script:
- cargo install forgejo-commit-path-rules
- forgejo-commit-path-rules
Create a .forgejo/commit-path-rules.toml file in your repository with rules:
# Use built-in templates
use_templates = ["custom-docs", "docs", "feature", "tests"]
# Define custom templates
[templates]
# All documentation commits must update the custom docs
custom_docs = { path = "custom-docs/", commit = "^docs:" }
[[rules]]
# All docs commits must include an update to the README
commit = "^docs:"
path = "README.md"
[[rules]]
# all features and docs commits must update the documentation
commit = "^(feat|docs):"
path = "docs/"
[[rules]]
# all fixes must only modify source files
commit = "^fix:"
path = "src/"
matching = "all"
suggestion = "All changes must be in src/"
Each rule consists of:
commit: A regex pattern matching commit messages that trigger this rulepath: A regex pattern matching file paths that should be modifiedsuggestion: (Optional) Custom suggestion message for rule violationsmatching : (Optional) Whether 'any' file (1 or more) can match, or 'all' files must match (default: any)When a commit matches the commit pattern, at least one file matching the path pattern must be modified.
The tool provides built-in templates for common patterns:
docs: Ensures documentation commits only modify documentation filesfeature: Ensures feature commits include both code and documentation changestests: Ensures test commits only modify test filesfixes: Ensures fix commits also update test filesYou can use these templates by adding them to the use_templates array in your configuration file.
You can also define custom templates in the templates section of your configuration file.
The tool provides helpful suggestions when rules are violated:
[WARN] Rule violated: ^docs:: README.md
[INFO] Commits matched pattern: ^docs:
[INFO] But paths didn't match pattern: README.md
[INFO] Suggestion: Documentation commits that match '^docs:' should include changes to paths matching 'README.md'. Please update the documentation accordingly.
The tool validates regex patterns in configuration files:
Error: Invalid regex pattern for path: '[unclosed'
Error: Invalid regex pattern for commit: '(unclosed'
The tool supports verbose logging for detailed debugging:
--verbose flag (-v)The tool provides comprehensive configuration validation:
The tool provides robust error handling with comprehensive diagnostics:
git clone https://codeberg.org/kemitix/forgejo-commit-path-rules.git
cd forgejo-commit-path-rules
cargo build --release
cargo test
workspace: This is automatically detected but can be overridden as a parameter.verbose: Enable verbose logging to get detailed information about the validation process.no-colour: Disable colour highlighting in log output..forgejo/commit-path-rules.tomlThis project is licensed under the MIT License - see the LICENSE file for details.
Contributions are welcome via the repository at https://codeberg.org/kemitix/forgejo-commit-path-rules