#commit-message #rules #path #consistency #pattern #enforce #repository

app forgejo-commit-path-rules

Enforce consistency between commit messages and file changes in your repository

3 releases

new 0.1.2 Mar 9, 2025
0.1.1 Mar 9, 2025
0.1.0 Mar 9, 2025

#124 in Filesystem

Download history

64 downloads per month

MIT license

50KB
1.5K SLoC

forgejo-commit-path-rules

Enforce consistency between commit messages and file changes in your repository.

It ensures that when specific types of changes are made (indicated by commit message patterns), corresponding documentation or code files are updated as well.

What it does

This tool validates your commits by:

  • Matching commit messages against configured regex patterns
  • For each matching pattern, checking if specified files have been modified
  • Enforcing documentation and code consistency through configurable rules

For example, you can ensure that:

  • New features (feat:) always update the README.md
  • API changes update both documentation and type definitions
  • Security patches update the security policy document
  • Breaking changes update the changelog

Why use it?

  • Maintain better documentation hygiene
  • Ensure critical files stay in sync with code changes
  • Automate consistency checks in your CI pipeline
  • Prevent merging changes that lack necessary documentation updates

LATEST version

See Tags for the latest version. Replace ${LATEST} in the examples below with the tag version (include any leading v).

code.forgejo.org Mirror

Main development can be followed on codeberg.org

There is a mirror on code.forgejo.org as kemitix/commit-path-rules

This mirror allows you to refer to the action as simply kemitix/commit-path-rules@${LATEST}.

Usage

Forgejo Action

jobs:
  tests:
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Check commit path rules
        uses: kemitix/commit-path-rules@${LATEST}

Configuration

Specify your rules in the file .forgejo/commit-path-rules.toml.

e.g.

[[rules]]
path = "README.md"
commit = "^feat:"

[[rules]]
path = "docs/"
commit = "^(feat|docs):"

These rules will ensure that:

  • README.md is updated for all feat: commits
  • at least one file in docs/ is updated for any feat: or docs: commits

Local CLI

You can also run the command in your local environment:

forgejo-commit-path-rules --workspace $PWD

Again, this will look for the .forgejo/commit-path-rules.toml file.

Example Output

The output will be similar to the following if there are any errors:

Forgejo Commit Path Rules!

Event: Push

Commits:
> 9ca572a feat: added deinit.sh
  - README.md
  - deinit.sh
- rule violated: ^(feat|docs):: docs/
Error:
   0: Missing required changes in selected path(s)

In this example, the commit 9ca572a has a commit message that starts with feat:, which matches against both rules from the example configuration above. The first rule wants the README.md file to be updated, and the second rule wants some file in docs/ to have been updated. The commit has the file README.md so it passes the first rule. However, it doesn't have any files in docs/, so it violates the second.

License

forgejo-commit-path-rules is released under the MIT License.

Dependencies

~28–43MB
~723K SLoC