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

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

3e049ed33195d00a8b745b16c63dce6e?s=47 Lee Wei
April 25, 2020

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

3e049ed33195d00a8b745b16c63dce6e?s=128

Lee Wei

April 25, 2020
Tweet

Transcript

  1. @clleew commitizen-tools What can we gain from crafting a git

    message convention?
  2. @clleew Slide

  3. @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"
  4. @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
  5. @clleew What is commitizen-tools?

  6. @clleew

  7. @clleew CLI tool for creating committing rules

  8. @clleew cookiecutter template to create customized commit rule

  9. @clleew The GitHub Actions to utilize the standardized messages

  10. @clleew The GitHub Actions to utilize the standardized messages that

    we're planning to add in the future
  11. @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
  12. @clleew

  13. @clleew

  14. @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)
  15. @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
  16. @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
  17. @clleew But... It's easy to forget all the guidelines when

    you enter "git commit"
  18. @clleew Commitizen

  19. @clleew Install Commitizen $ python -m pip install pipx $

    python -m pipx install commitizen $ cz # or git cz
  20. @clleew cz init Initialize commitizen configuration

  21. @clleew cz init Initialize commitizen configuration

  22. @clleew cz init Initialize commitizen configuration

  23. @clleew [tool.commitizen] name = "cz_conventional_commits" version = "0.0.1" tag_format =

    "$version" Commitizen Configuration
  24. @clleew cz commit type of this change A hint for

    users to break down multiple changes into separate commits
  25. @clleew cz commit scope of this change

  26. @clleew cz commit
 a short description

  27. @clleew cz commit
 whether it's a breaking change

  28. @clleew cz commit
 detail description of this change

  29. @clleew cz commit
 footer reference to the ticket or issue

    related to this change
  30. @clleew Standardized git commits

  31. @clleew Standardized git commits git log --format="%s"

  32. @clleew What if I forget to use "cz commit" to

    do git commit?
  33. @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
  34. @clleew git will block it if your commit does not

    follow the rule.
  35. @clleew git will block it if your commit does not

    follow the rule.
  36. @clleew git will block it if your commit does not

    follow the rule.
  37. @clleew How can we utilize these standardize commit messages? •

    Auto versioning • Auto generate changelog (beta)
  38. @clleew Semantic Versioning x.y.z MAJOR Minor Patch

  39. @clleew • MAJOR: incompatible API changes • MINOR: add backwards

    compatible functionality • PATCH: make backwards compatible bug fixes Semantic Versioning
  40. @clleew Bump Version • MAJOR: breaking change • MINOR: feat

    • PATCH: fix, refactor, perf
  41. @clleew Bump Version • MAJOR: breaking change • MINOR: feat

    • PATCH: fix, refactor, perf
  42. @clleew Bump Version $ cz bump

  43. @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
  44. @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
  45. @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" ]
  46. @clleew Auto generate changelog • It's a beta feature. •

    Installation $ pip install git+https://github.com/commitizen-tools/ commitizen.git@command-changelog
  47. @clleew Keep a changelog

  48. @clleew Auto generate changelog $ cz changelog

  49. @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
  50. @clleew Join us and make commitizen-tools better

  51. @clleew Reference • commitizen-tools • Conventional Commits • Semantic Versioning

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