Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add keyboard shortcuts to prompt #406

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

Merged
Lee-W merged 6 commits into commitizen-tools:master from zevisert:master
Aug 13, 2021
Merged

Add keyboard shortcuts to prompt #406

Lee-W merged 6 commits into commitizen-tools:master from zevisert:master
Aug 13, 2021

Conversation

Copy link
Contributor

@zevisert zevisert commented Jul 17, 2021

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

Copy link
Contributor Author

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

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?

Copy link
Member

woile commented Jul 20, 2021

This is great! I like it!

Lee-W reacted with thumbs up emoji

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 and woile reacted with thumbs up emoji

@Lee-W Lee-W added the needs: test-case new to add test case to prove the functionality label Jul 26, 2021
zevisert added 2 commits August 6, 2021 10:26
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 
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.

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

woile reacted with thumbs up emoji

Copy link

codecov bot commented Aug 10, 2021
edited
Loading

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.

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.

Copy link
Contributor Author

zevisert commented Aug 12, 2021
edited
Loading

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.
woile and Lee-W reacted with hooray emoji woile and Lee-W reacted with rocket emoji

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

Lee-W commented Aug 13, 2021

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

zevisert reacted with hooray emoji

@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
Reviewers

@Lee-W Lee-W Lee-W approved these changes

Assignees
No one assigned
Labels
needs: test-case new to add test case to prove the functionality
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /