Skip to main content

Python commitizen client tool

Project description

Python 3 command line utility to standardize commit messages

Conventional Commits PyPI Package latest release Supported versions Example running commitizen

About

This is an interactive tool to commit based on some rules (like conventional commits).

It comes with some defaults commit styles, like conventional commits and jira and it’s easily extendable.

It’s useful for teams, because it is possible to standardize the commiting style.

Installation

pip install commitizen

For beta

sudo pip3 install -U commitizen --pre

Information

This client tool prompts the user with information about the commit.

Based on conventional commits

This is an example of how the git messages history would look like:

BREAKING CHANGE: command send has been removed
fix: minor typos in code
feat: new command update
docs: improved commitizens tab in readme
feat(cz): jira smart commits
refactor(cli): renamed all to ls command
feat: info command for angular
docs(README): added badges
docs(README): added about, installation, creating, etc
feat(config): new loads from ~/.cz and working project .cz .cz.cfg and setup.cfg

Commitizens

These are the available commiting styles by default:

The installed ones can be checked with:

cz ls

Commiting

Run in your terminal

cz commit

or the shortcut

cz c

Usage

usage: cz [-h] [--debug] [-n NAME] [--version]
        {ls,commit,c,example,info,schema} ...

Commitizen is a cli tool to generate conventional commits.
For more information about the topic go to https://conventionalcommits.org/

optional arguments:
-h, --help            show this help message and exit
--debug               use debug mode
-n NAME, --name NAME  use the given commitizen
--version             get the version of the installed commitizen

commands:
{ls,commit,c,example,info,schema}
    ls                  show available commitizens
    commit (c)          create new commit
    example             show commit example
    info                show information about the cz
    schema              show commit schema

Configuration

You can create in your project folder a file called .cz, .cz.cfg or in your setup.cfg or if you want to configure the global default in your user’s home folder a .cz file with the following information:

[commitizen]
name = cz_conventional_commits

Creating a commiter

Create a file starting with cz_ for example cz_jira.py. This prefix is used to detect the plugin. Same method flask uses

Inherit from BaseCommitizen and you must define questions and message. The others are optionals.

from commitizen import BaseCommitizen

class JiraCz(BaseCommitizen):

    def questions(self):
        """Questions regarding the commit message.

        Must have 'whaaaaat' format.
        More info: https://github.com/finklabs/whaaaaat/

        :rtype: list
        """
        questions = [
            {
                'type': 'input',
                'name': 'title',
                'message': 'Commit title'
            },
            {
                'type': 'input',
                'name': 'issue',
                'message': 'Jira Issue number:'
            },
        ]
        return questions

    def message(self, answers):
        """Generate the message with the given answers.

        :type answers: dict
        :rtype: string
        """
        return '{0} (#{1})'.format(answers['title'], answers['issue'])

    def example(self):
        """Provide an example to help understand the style (OPTIONAL)
        Used by cz example.

        :rtype: string
        """
        return 'Problem with user (#321)'

    def schema(self):
        """Show the schema used (OPTIONAL)

        :rtype: string
        """
        return '<title> (<issue>)'

    def info(self):
        """Explanation of the commit rules. (OPTIONAL)
        :rtype: string
        """
        return 'We use this because is useful'


discover_this = JiraCz  # used by the plugin system

The next file required is setup.py modified from flask version

from distutils.core import setup

setup(
    name='JiraCommitizen',
    version='0.1.0',
    py_modules=['cz_jira'],
    license='MIT',
    long_description='this is a long description',
    install_requires=['commitizen']
)

So at the end we would have

.
├── cz_jira.py
└── setup.py

And that’s it, you can install it without uploading to pypi by simply doing pip install . If you feel like it should be part of the repo, create a PR.

Python 2 support

There’s no longer support for python 2. Nor planned suppport.

Feel free to create a PR.

Contributing

  1. Clone the repo.

  2. Add your modifications

  3. Run python setup.py test --pytest-args --cov=./commitizen

Testing

pytest -s –cov-report term-missing –cov=commitizen tests/

Project details


Release history Release notifications | RSS feed

Download files

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

Source Distribution

commitizen-1.0.0b2.tar.gz (12.1 kB view details)

Uploaded Source

Built Distribution

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

commitizen-1.0.0b2-py3-none-any.whl (25.5 kB view details)

Uploaded Python 3

File details

Details for the file commitizen-1.0.0b2.tar.gz.

File metadata

  • Download URL: commitizen-1.0.0b2.tar.gz
  • Upload date:
  • Size: 12.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/0.12.8 CPython/3.6.7 Linux/4.15.0-43-generic

File hashes

Hashes for commitizen-1.0.0b2.tar.gz
Algorithm Hash digest
SHA256 9eef43c4489508ee51e3b35b61742fdc3791d1f32535b7b03b9774a5d1b065a0
MD5 c43daa5bf6aeabb2f1c9b68877a1aaaf
BLAKE2b-256 d73f1006876b94bb93d7c1f3442bdc787ca9adf2695904c6a48262a7e30e9f38

See more details on using hashes here.

File details

Details for the file commitizen-1.0.0b2-py3-none-any.whl.

File metadata

  • Download URL: commitizen-1.0.0b2-py3-none-any.whl
  • Upload date:
  • Size: 25.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/0.12.8 CPython/3.6.7 Linux/4.15.0-43-generic

File hashes

Hashes for commitizen-1.0.0b2-py3-none-any.whl
Algorithm Hash digest
SHA256 be8b49167b26a194d05431b6b2efb03644543474435b96ef28f8517c7912df16
MD5 023eaf0e8b2f187ddbf7fb8b913cbbc1
BLAKE2b-256 fbf34337a75ea858522c9d2c675b47e7bfbbaed9ae23c0cf9e102a7073be1b14

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