Skip to main content

Commisery

Commisery is a package to help check whether given commit messages adhere to Conventional Commits. Specifically, it checks the syntax and some small aspects of the semantics.

The purpose of this is severalfold:

  1. Achieving a common layout for commit messages in order to help humans more quickly extract useful information from them.
  2. Making these messages partially machine processable in order to classify changes for proper version management.
  3. Identifying a subset of common mistakes that render a message useless to your future self or colleagues.

The latter goal usually requires your commit messages to answer these questions:

  • What: a short summary of what you changed in the subject line.
  • Why: what the intended outcome of the change is (arguably the most important piece of information that should go into a message).
  • How: if multiple approaches for achieving your goal were available, you also want to explain why you chose the used implementation strategy.
    • Note that you should not explain how your change achieves your goal in your commit message. That should be obvious from the code itself. If you cannot achieve that clarity with the used programming language, use comments within the code instead.
    • The commit message is primarily the place for documenting the why.

Unfortunately, checking whether these last questions get answered is also the most difficult to do automatically. This tool only checks for a few common errors other than syntax errors:

  1. Usage of Jira ticket numbers in the subject line.
    • Because the subject line is expensive real estate every character should be most efficiently used to convey meaning to humans.
    • Jira ticket numbers are not equal to the tickets themselves and thus convey very little information. These ticket numbers should go in message footers where tools can still extract them for automatic linking.
  2. Using non-imperative verb forms (adds, added or adding instead of add) in the subject line.
    • These other forms convey no more meaning but use extra precious characters.
  3. Referring to review comments that cannot be found anywhere in the commit history itself.
    • Commit messages should be self-contained. Only mentioning that a commit is created in response to a review comment, without mentioning the reasoning of that comment is clearly not self-contained.
    • Whenever your workflow permits it, prefer amending the original commit (or using --fixup) instead.
    • If your workflow doesn't permit that, or it seems suboptimal in a given context, describe what, why and how you are changing (as mentioned before).

Installation

You can install this package with pip as follows:

pip3 install --user --upgrade commisery

Usage

You can verify commit messages with the included CLI tool:

$ commisery-verify-msg 8c3349528888a62382afd056eea058843dfb7690
$ commisery-verify-msg master
$ commisery-verify-msg :/'refactor'
$ commisery-verify-msg .git/COMMIT_EDITMSG
$ commisery-verify-msg my-own-message.txt

The exit code of that tool will be non-zero if and only if it found errors in the given commit message.

After that you can use it as a hook in Git to check messages you wrote by creating a .git/hooks/commit-msg file with these contents:

#!/bin/sh
exec commisery-verify-msg "$@"

The CLI tool also handles commit-ish revision ranges adhering to the git rev-list format:

$ commisery-verify-msg HEAD~..HEAD
$ commisery-verify-msg HEAD^2~4 ^HEAD^2~6 ^HEAD^3~2
$ commisery-verify-msg master..feat/my-feature
$ commisery-verify-msg HEAD@{yesterday}..HEAD
$ commisery-verify-msg HEAD@{upstream}..HEAD
$ commisery-verify-msg :/'refactor'..HEAD
$ commisery-verify-msg 2fff3d8..8c33495

Commisery allows for custom behavior as well:

  • a custom list of accepted Conventional Commit tags can be provided
  • the presence of a Jira-style ticket reference within the specified commit message (or range) can be enforced

Refer to the built-in help for information on these optional parameters.

$ commisery-verify-msg --help

GitHub support

You can use Commisery based on a GitHub PullRequest by installing the package with the extra github:

pip3 install --user --upgrade commisery[github]

You can verify the Pull Request title and commit messages with the included CLI tool:

$ commisery-verify-github-pullrequest --token GITHUB_TOKEN --repository owner/repo --pullrequest-id 1

The exit code of that tool will be non-zero if and only if it found errors in the given Pull Request.

Hopic

Using it as a check in Hopic can be accomplished with a configuration fragment like this:

phases:
  style:
    commit-messages:
      - python3 -m virtualenv --clear venv
      - venv/bin/python -m pip install --upgrade 'commisery>=0,<1'
      # Require each commit message to adhere to our requirements
      - foreach: AUTOSQUASHED_COMMIT
        sh: venv/bin/python venv/bin/commisery-verify-msg ${AUTOSQUASHED_COMMIT}
      # Optional: check the produced merge commit message too (this includes the PR title)
      - venv/bin/python venv/bin/commisery-verify-msg HEAD

This exact form can also be used through the commisery template:

phases:
  style:
    commit-messages: !template "commisery"

Metadata

Release files for commisery 0.10.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for commisery 0.10.0
File Size Uploaded Provenance
commisery-0.10.0.tar.gz 29.9 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for commisery 0.10.0
File Interpreter ABI Platform
commisery-0.10.0-py3-none-any.whl Python 3 none any Details

Total release size: 53.7 kB

Release files / commisery-0.10.0.tar.gz

Download URL commisery-0.10.0.tar.gz
Size 29.9 kB
Tags Source
SHA-256 checksum
How to use checksums
c1cf2f7d201ddd1d1a495e1d2f7ed9680c4b69d9e88f69be196dc93d6b84c724
BLAKE2b-256 checksum
How to use checksums
808cd32d4de6184baf2009b179d0a4936dec2a8276f06e9be93857ac6b15deec
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.3 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.11 tqdm/4.64.0 importlib-metadata/4.8.3 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.5 CPython/3.6.9

Release files / commisery-0.10.0-py3-none-any.whl

Download URL commisery-0.10.0-py3-none-any.whl
Size 23.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7c2198a1bb5939b879d6583ca3ebea799a1247964d3372674fe6d443bea6a4b1
BLAKE2b-256 checksum
How to use checksums
c19c152eab7eb308c68d2c7095001c611e5df8c21d0e038087ab2bad871d53f9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.3 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.11 tqdm/4.64.0 importlib-metadata/4.8.3 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.5 CPython/3.6.9

Security for commisery 0.10.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page