Skip to content

Conversation

zevisert
Copy link
Contributor

Description

See the suggestion in #380.

  • feat(prompt): add keyboard shortcuts with config option

    Also added chore option to conventional_commits choices

This PR adds a config option called use_shortcuts which enables shortcuts in conventional commit choices. It defaults to false, so it'd be opt-in for now. In #380, the suggestion was to add the use_shortcuts: bool kwarg to questionary.prompt in commands/commit.py, but questionary passes this on to every question, and subsequently throws for prompt types that don't support use_shortcuts. The solution was to add use_shortcuts to the first question in cz/conventional_commits/conventional_commits.py instead.

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

@zevisert
Copy link
Contributor Author

I'll add tests later if you like the change. I noticed there wasn't complete approval in #380 yet.

@Lee-W
Copy link
Member

Lee-W commented Jul 17, 2021

@zevisert Thanks for you contribution! This feature looks good to me @woile What do you think?

@woile
Copy link
Member

woile commented Jul 20, 2021

This is great! I like it!

@zevisert
Copy link
Contributor Author

Great, I'll follow up with some tests and docs in the next day or two - and sure I'll drop that chore option. I didn't mean to submit that here, that's just from me fiddling around.

@Lee-W Lee-W added the needs: test-case new to add test case to prove the functionality label Jul 26, 2021
Only testing that cz_conventional_commits has keyboard shortcuts configured, and that the use_shortcuts config option is known. Actually mocking and asserting against what's written to stdout is a footgun

#406, #380
@zevisert
Copy link
Contributor Author

zevisert commented Aug 6, 2021

Hey sorry for the delay! I rebased out the chore option, and added a test to ensure all of the options in any select questions in cz_conventional_commits has a keyboard key defined. Actually mocking out and asserting the shortcuts render in the terminal when the config option is enabled was a little too complicated IMO. I also updated the config tests to be aware of the new config option.

@Lee-W
Copy link
Member

Lee-W commented Aug 7, 2021

Thanks for your update! But might need your help to reformat the code through ./scripts/format

@codecov
Copy link

codecov bot commented Aug 10, 2021

Codecov Report

Merging #406 (50ddc72) into master (184c439) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #406   +/-   ##
=======================================
  Coverage   97.90%   97.90%           
=======================================
  Files          39       39           
  Lines        1381     1383    +2     
=======================================
+ Hits         1352     1354    +2     
  Misses         29       29           
Flag Coverage Δ
unittests 97.90% <100.00%> (+<0.01%) ⬆️

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

Impacted Files Coverage Δ
...en/cz/conventional_commits/conventional_commits.py 100.00% <ø> (ø)
commitizen/defaults.py 100.00% <ø> (ø)
commitizen/__version__.py 100.00% <100.00%> (ø)
commitizen/commands/commit.py 98.33% <100.00%> (+0.05%) ⬆️

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 50d57ac...50ddc72. Read the comment docs.

@zevisert
Copy link
Contributor Author

Docs are updated, and I moved where we check the config for use_shortcuts to the Commit class, so that any BaseCommitizen class automatically gets access to this new feature. Thinking about my team and I, since we like to have chore included in our custom conventional commits rules.

@zevisert
Copy link
Contributor Author

zevisert commented Aug 12, 2021

Also, I mentioned it in the docs, but when there's no key provided, questionary conveniently falls back to numbering the options. This means that 3rd party templates aren't broken by this new setting! 🎉

eg.; Using the customize settings from the docs with use_shortcuts enabled:

$ poetry run cz commit
? Select the type of change you are committing (Use shortcuts or arrow keys)
 » 1) feature: A new feature.
   2) bug fix: A bug fix.

@zevisert zevisert requested a review from Lee-W August 12, 2021 01:58
@Lee-W
Copy link
Member

Lee-W commented Aug 13, 2021

didn't expect that handy feature. it's great. let's merge this one!

@Lee-W Lee-W merged commit dedcb2d into commitizen-tools:master Aug 13, 2021
Lee-W pushed a commit that referenced this pull request Aug 13, 2021
Only testing that cz_conventional_commits has keyboard shortcuts configured, and that the use_shortcuts config option is known. Actually mocking and asserting against what's written to stdout is a footgun

#406, #380
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs: test-case new to add test case to prove the functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants