Upgrade to Pro — share decks privately, control downloads, hide ads and more …

commitizen-tools/ What can we gain from craftin...

Lee Wei
April 25, 2020

commitizen-tools/ What can we gain from crafting a git message convention? @ Remote Python Pizza 2020

Lee Wei

April 25, 2020
Tweet

More Decks by Lee Wei

Other Decks in Technology

Transcript

  1. @clleew $ cat speaker.py __name__ = "Wei Lee / 李唯"

    __position__ = [ "Software Engineer @ Rakuten Slice", "Volunteer @ PyCon Taiwan" ] __twitter__ = " @clleew" __github__ = " Lee-W" __blog__ = " http://lee-w.github.io"
  2. @clleew __end_of_cfp__ = "26 Apr 23:59 (AoE)" __note__ = "We

    accept remote presentation!" __date__ = "5-6 Sep" __location__ = "Tainan, Taiwan" __twitter__ = " @PyConTW" $ cat pycontw_2020.py
  3. @clleew • Why commit message matters? • Use Commitizen to

    build a commit message convention • How can we utilize these standardized messages? What I’m going to talk about
  4. @clleew Why not use "update" as a commit message? •

    Hard to find the right commit to rollback • Hard to know the trace of this change during code review • Tend to make a lot of changes in a single commit
 (because you don't know how to describe these changes)
  5. @clleew Why should we write good commit message? • Guide

    teams on how code changes should be made • Save reviewers' time to know the intention of changes • Give newcomer a clear view of the evolvement of projects
  6. @clleew How to write good commit messages? 1. Separate subject

    from body with a blank line 2. Limit the subject line to 50 characters 3. Capitalize the subject line 4. Do not end the subject line with a period 5. Use the imperative mood in the subject line 6. Wrap the body at 72 characters 7. Use the body to explain what and why vs. how
  7. @clleew Install Commitizen $ python -m pip install pipx $

    python -m pipx install commitizen $ cz # or git cz
  8. @clleew cz commit type of this change A hint for

    users to break down multiple changes into separate commits
  9. @clleew Enforce commit check through pre-commit 1.Create .pre-commit-config.yaml
 
 


    
 
 2.Install pre-commit hook repos: - repo: https://github.com/commitizen-tools/commitizen rev: v1.18.1 hooks: - id: commitizen stages: [commit-msg] $ python -m pipx install pre-commit $ pre-commit install -t commit-msg
  10. @clleew How can we utilize these standardize commit messages? •

    Auto versioning • Auto generate changelog (beta)
  11. @clleew • MAJOR: incompatible API changes • MINOR: add backwards

    compatible functionality • PATCH: make backwards compatible bug fixes Semantic Versioning
  12. @clleew The commit with the highest version to bump is

    feat (The original version of the sample project is 1.2.0.) Bump Version $ cz bump
  13. @clleew message tag to create: 1.3.0 increment detected: MINOR The

    commit with the highest version to bump is feat (The original version of the sample project is 1.2.0.) Bump Version $ cz bump
  14. @clleew Bump Version in Source File [tool.commitizen] name = "cz_conventional_commits"

    version = "0.0.1" tag_format = "$version" version_files = [ "my_project/__init__.py" ]
  15. @clleew Auto generate changelog • It's a beta feature. •

    Installation $ pip install git+https://github.com/commitizen-tools/ commitizen.git@command-changelog
  16. @clleew Auto generate changelog $ cz changelog # CHANGELOG ##

    Unreleased ### feat - add cov task to check test coverage - make scripts a package - add pylint task - add mypy, flake8 style check - add reformat task to reformat code through black
  17. @clleew Reference • commitizen-tools • Conventional Commits • Semantic Versioning

    • Keep a changelog • How to Write a Git Commit Message