Skip to main content

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

Project description

Commit Check

PyPI CI Quality Gate Status pre-commit

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 that it is easier to read and enforces writing descriptive commits. Besides that, having conventional commits and branch naming makes it possible to parse them and use them for something else, like:

  • triggering specific types of builds
  • generating automatically the version or a changelog
  • easy to identify branch according to the branch type

Installation

Global installation

sudo pip3 install -U commit-check

User installation

pip install -U commit-check

TODO: On macOS, it can also be installed via homebrew:

brew install commit-check

Install from git repo

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

Usage

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.

If you want to skip the commit-check, you can use the option -n or --no-verify.

Integrating with pre-commit

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

Integrating with GitHub Action

name: commit-check

on: pull_request

jobs:
  commit-check:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: commit-check/commit-check@v0
        id: check
        with:
          message: true
          branch: true

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 ||
 _.' `-' '._  _.' `-' '._  _.' `-' '._  _.' `-' '._  _.' `-' '.
(.-./`-'\.-.)(.-./`-`\.-.)(.-./`-`\.-.)(.-./`-'\.-.)(.-./`-`\.-.)
 `-'     `-'  `-'     `-'  `-'     `-'  `-'     `-'  `-'     `-'

Commit rejected.

Invalid commit message. it does'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

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. it does't match regex: ^(bugfix|feature|release|hotfix|task)\/.+|(master)|(main)

Branches must begin with these types: bugfix/ feature/ release/ hotfix/ task/ or master main

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

commit_check-0.2.1-py3-none-any.whl (9.6 kB view details)

Uploaded Python 3

File details

Details for the file commit_check-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: commit_check-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 9.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.0

File hashes

Hashes for commit_check-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 29170889e233bc75f68a7a7757bc344c2dcf26e3aabc91bef9ec09cb3d66a421
MD5 307e517efed5a85fcf998e90753b54ea
BLAKE2b-256 f7dbeb3b1ab5b0b3761a9367f5fd4fbdbabcb38ed2cfd2350fcc171f3cd23e10

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page