/commit-check

Check commit message formatting, branch naming, commit author, email, and more. The open source alternative to Yet Another Commit Checker.

Primary LanguagePythonMIT LicenseMIT

Commit Check

PyPI CI Quality Gate Status pre-commit.ci status

Check commit message formatting, branch naming, referencing Jira tickets, and more

About

commit-check is a tool designed for teams.

Its main purpose is to standardize the format of commit messages and branch naming.

The reason behind it is and makes it possible, like:

  • writing descriptive commit is easy to read
  • identify branch according to the branch type
  • triggering specific type of commit/branch CI build
  • automatically generate changelogs

Usage

There are a variety of ways you can use commit-check:

Running as CLI

Global installation

sudo pip3 install -U commit-check

User installation

pip install -U commit-check

Install from git repo

pip install git+https://github.com/commit-check/commit-check.git@main

Then you can run commit-check command line. More about commit-check --help please see docs.

Running as pre-commit hook

Add .commit-check.yml

Create a config file .commit-check.yml under your repository, e.g. .commit-check.yml

The content of the config file should be in the following format.

checks:
- check: message
    regex: '^(build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test){1}(\([\w\-\.]+\))?(!)?: ([\w ])+([\s\S]*)'
    error: "<type>: <description>

    For Example. feat: Support new feature xxxx

    Between type and description MUST have a colon and space.

    More please refer to https://www.conventionalcommits.org"
- check: branch
    regex: '^(bugfix|feature|release|hotfix|task)\/.+|(master)|(main)|(HEAD)|(PR-.+)'
    error: "Branches must begin with these types: bugfix/ feature/ release/ hotfix/ task/"

Use default configuration

  • If you do not set .commit-check.yml, commit-check will use the default configuration. i.e. the commit message will follow the rules of conventional commits, branch naming follow bitbucket branching model.

Integrating with pre-commit

Tip

Make sure pre-commit is installed.

Install the commit-msg hook in your project repo.

pre-commit install --hook-type prepare-commit-msg

Or have default_install_hook_types: [pre-commit, prepare-commit-msg] in your .pre-commit-config.yaml.

default_install_hook_types: [pre-commit, prepare-commit-msg]

-   repo: https://github.com/commit-check/commit-check
    rev: v0.1.4
    hooks:
    -   id: check-message
    -   id: check-branch

Running as GitHub Action

Please see commit-check/commit-check-action

Example

Check commit message failed

Commit rejected by Commit-Check.

  (c).-.(c)    (c).-.(c)    (c).-.(c)    (c).-.(c)    (c).-.(c)
   / ._. \      / ._. \      / ._. \      / ._. \      / ._. \
 __\( C )/__  __\( H )/__  __\( E )/__  __\( C )/__  __\( K )/__
(_.-/'-'\-._)(_.-/'-'\-._)(_.-/'-'\-._)(_.-/'-'\-._)(_.-/'-'\-._)
   || E ||      || R ||      || R ||      || O ||      || R ||
 _.' '-' '._  _.' '-' '._  _.' '-' '._  _.' '-' '._  _.' '-' '._
(.-./`-´\.-.)(.-./`-´\.-.)(.-./`-´\.-.)(.-./`-´\.-.)(.-./`-´\.-.)
 `-´     `-´  `-´     `-´  `-´     `-´  `-´     `-´  `-´     `-´

Invalid commit message => test
It doesn't match regex: ^(build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test){1}(\([\w\-\.]+\))?(!)?: ([\w ])+([\s\S]*)

The commit message should be structured as follows:

<type>[optional scope]: <description>
[optional body]
[optional footer(s)]

More details please refer to https://www.conventionalcommits.org
Suggest to run => git commit --amend

Check branch naming failed

Commit rejected by Commit-Check.

  (c).-.(c)    (c).-.(c)    (c).-.(c)    (c).-.(c)    (c).-.(c)
   / ._. \      / ._. \      / ._. \      / ._. \      / ._. \
 __\( C )/__  __\( H )/__  __\( E )/__  __\( C )/__  __\( K )/__
(_.-/'-'\-._)(_.-/'-'\-._)(_.-/'-'\-._)(_.-/'-'\-._)(_.-/'-'\-._)
   || E ||      || R ||      || R ||      || O ||      || R ||
 _.' '-' '._  _.' '-' '._  _.' '-' '._  _.' '-' '._  _.' '-' '._
(.-./`-´\.-.)(.-./`-´\.-.)(.-./`-´\.-.)(.-./`-´\.-.)(.-./`-´\.-.)
 `-´     `-´  `-´     `-´  `-´     `-´  `-´     `-´  `-´     `-´

Commit rejected.

Invalid branch name => test
It doesn't match regex: ^(bugfix|feature|release|hotfix|task)\/.+|(master)|(main)|(HEAD)|(PR-.+)

Branches must begin with these types: bugfix/ feature/ release/ hotfix/ task/
Suggest to run => git checkout -b type/branch_name

Versioning

Versioning follows Semantic Versioning.

Have question or feedback?

To provide feedback (requesting a feature or reporting a bug) please post to issues.

License

The scripts and documentation in this project are released under the MIT License

ko-fi