Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(commands/commit): apply prepare-commit-msg hook #250

Open
wants to merge 2 commits into
base: master
from

Conversation

@saygox
Copy link

saygox commented Aug 14, 2020

Types of changes

  • Bug fix
  • New feature
  • Refactoring
  • Breaking change (any change that would cause existing functionality to not work as expected)
  • Documentation update
  • Other (please describe)

Description

invoke cz commit from git prepare-commit-msg hook

Checklist

  • Add test cases to all the changes you introduce
  • Run ./script/format and ./script/test locally to ensure this change passes linter check and test
  • Test the changes on the local machine manually
  • Update the documentation for the changes

Steps to Test This Pull Request

  1. Create a fake repo
  2. Add prepare-commit-msg hook
  3. Start comitting

Expected behavior

  • hook invokes cz commit
  • Editor is invoked after questionary
  • commit message is filled by cz commit

Additional context

  • #249
  • test only in linux
saygox added 2 commits Aug 13, 2020
add --commit-msg-file argument
for pass the python-check (3.8)
@codecov
Copy link

codecov bot commented Aug 14, 2020

Codecov Report

Merging #250 into master will increase coverage by 0.13%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #250      +/-   ##
==========================================
+ Coverage   96.58%   96.71%   +0.13%     
==========================================
  Files          33       33              
  Lines         908      945      +37     
==========================================
+ Hits          877      914      +37     
  Misses         31       31              
Flag Coverage Δ
#unittests 96.71% <100.00%> (+0.13%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
commitizen/cli.py 97.36% <ø> (ø)
commitizen/commands/bump.py 90.58% <ø> (ø)
commitizen/git.py 95.50% <ø> (ø)
commitizen/__version__.py 100.00% <100.00%> (ø)
commitizen/commands/check.py 100.00% <100.00%> (ø)
commitizen/commands/commit.py 98.92% <100.00%> (+0.64%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 750213c...09fa312. Read the comment docs.

@Lee-W
Copy link
Member

Lee-W commented Aug 20, 2020

Hi, although I've not yet had the time to fully review the code, I just test it on my local machine and failed.

This is the .pre-commit-config.yaml I used.

default_stages: [push]
repos:
  - repo: https://github.com/pre-commit/pre-commit-hooks
    rev: v3.1.0
    hooks:
      - id: check-vcs-permalinks
      - id: end-of-file-fixer
      - id: trailing-whitespace
        args: [--markdown-linebreak-ext=md]
      - id: debug-statements
      - id: no-commit-to-branch

  - repo: https://github.com/saygox/commitizen
    rev: 09fa312b7846850f44f7860632685189e37c1bec
    hooks:
      - id: commitizen-prepare-commit-msg
        stages: [prepare-commit-msg

The command I used.

mkdir test
cd test
git init

# add .pre-commit-config.yaml

pre-commit install -t prepare-commit-msg
git commt

The error message

  File "/.../.cache/pre-commit/repof8ns4eua/py_env-python3/bin/cz", line 8, in <module>
    sys.exit(main())
  File "/.../.cache/pre-commit/repof8ns4eua/py_env-python3/lib/python3.7/site-packages/commitizen/cli.py", line 286, in main
    args.func(conf, vars(args))()
  File "/.../.cache/pre-commit/repof8ns4eua/py_env-python3/lib/python3.7/site-packages/commitizen/commands/commit.py", line 94, in __call__
    m = self.prompt_commit_questions()
  File "/.../.cache/pre-commit/repof8ns4eua/py_env-python3/lib/python3.7/site-packages/commitizen/commands/commit.py", line 63, in prompt_commit_questions
    answers = questionary.prompt(questions, style=cz.style)
  File "/.../.cache/pre-commit/repof8ns4eua/py_env-python3/lib/python3.7/site-packages/questionary/prompt.py", line 97, in prompt
    answer = question.unsafe_ask(patch_stdout)
  File "/.../.cache/pre-commit/repof8ns4eua/py_env-python3/lib/python3.7/site-packages/questionary/question.py", line 59, in unsafe_ask
    return self.application.run()
  File "/.../.cache/pre-commit/repof8ns4eua/py_env-python3/lib/python3.7/site-packages/prompt_toolkit/application/application.py", line 816, in run
    self.run_async(pre_run=pre_run, set_exception_handler=set_exception_handler)
  • Python version: 3.7
  • OS: macOS 10.15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants
You can’t perform that action at this time.