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

Add support to skip prompting filled info #536

Closed
wants to merge 2 commits into from

Conversation

momsse
Copy link

@momsse momsse commented Feb 5, 2021

Description

Add support to an option that will skip asking gitmoji/title/message when they are filled.

Issue: #534

Tests

  • All tests passed.

@codecov
Copy link

codecov bot commented Feb 5, 2021

Codecov Report

Merging #536 (6771aeb) into master (9c8ba88) will increase coverage by 2.02%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #536      +/-   ##
==========================================
+ Coverage   90.17%   92.19%   +2.02%     
==========================================
  Files          22       23       +1     
  Lines         173      205      +32     
  Branches       25       35      +10     
==========================================
+ Hits          156      189      +33     
  Misses         14       14              
+ Partials        3        2       -1     
Impacted Files Coverage Δ
src/commands/config/prompts.js 100.00% <ø> (ø)
src/commands/commit/index.js 100.00% <100.00%> (ø)
src/commands/commit/prompts.js 80.00% <100.00%> (+22.85%) ⬆️
src/commands/config/index.js 100.00% <100.00%> (ø)
src/utils/configurationVault.js 100.00% <100.00%> (ø)
src/utils/getDefaultAnswers.js 100.00% <100.00%> (ø)
src/utils/getDefaultCommitContent.js 100.00% <100.00%> (ø)
src/commands/commit/guard.js 100.00% <0.00%> (+16.66%) ⬆️

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 9c8ba88...6771aeb. Read the comment docs.

Copy link
Owner

@carloscuesta carloscuesta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for sending a PR!

Overall code is a little bit complex just pointed out some questions and comments


return [
{
if (!defaultAnswers.gitmoji) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we stick to the old format? I just want to keep immutability in the codebase as much as possible 🙏🏼

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure

},
{
name: CONFIGURATION_PROMPT_NAMES.SKIP_PROMPTING_FILLED_INFO,
message: 'Skip prompting already filled info',
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to clarify better what this option is doing. For you this might be already familiar but for someone who uses the cli and doesn't looks into the PR issues I don't think Skip prompting already filled info is an understandable message, what information is referring this to ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure perhaps a more verbose sentence of what it does ?

Skip prompting for gitmoji, title and message commit when retrieved

@@ -5,7 +5,8 @@ export const CONFIGURATION_PROMPT_NAMES = {
AUTO_ADD: 'autoAdd',
EMOJI_FORMAT: 'emojiFormat',
SCOPE_PROMPT: 'scopePrompt',
SIGNED_COMMIT: 'signedCommit'
SIGNED_COMMIT: 'signedCommit',
SKIP_PROMPTING_FILLED_INFO: 'skipPromptingFilledInfo'
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as for this option, is a little bit ambiguous

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, do you have some suggestion ?

Comment on lines +42 to +51
let gitmoji = null
let title = commitFileContent[COMMIT_TITLE_LINE_INDEX]

const gitmojiRegexResult =
configurationVault.getEmojiFormat() === EMOJI_COMMIT_FORMATS.CODE
? gitmojiCodeRegex.exec(title)
: gitmojiSymbolRegex.exec(title)
if (gitmojiRegexResult && gitmojiRegexResult.length === 3) {
;[, gitmoji, title] = gitmojiRegexResult
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall this is fairly complex, there are some magic numbers can you explain what are you trying to do in this block?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Basically extracting the gitmoji from the title (3 is the size of the regex array when it succeed).

I can extract the logic to his own function to make it easier to read. Is it fair enough ?

Comment on lines +12 to +13
const gitmojiSymbolRegex = /^(\p{Emoji_Presentation})\s*(.*)/gu
const gitmojiCodeRegex = /^(:[a-zA-Z_]+:)\s*(.*)/gu
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To skip the gitmoji prompt I have to detect if the user has already filled it on the title part of the commit. This is the regex to do the job.

Comment on lines -6 to -7
import getDefaultCommitContent from '../../utils/getDefaultCommitContent'
import { type CommitMode } from './index'
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why we moved this outside of this module?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because I need the result of the function call for getDefaultAnswers and prompts. To avoid call it twice I moved it down to commit/index

Comment on lines +27 to +28
const commitContent = getDefaultCommitContent(mode)
const defaultAnswers = getDefaultAnswers(commitContent)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why we moved this at commit level?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same answer as above.

@momsse
Copy link
Author

momsse commented Feb 7, 2021

To resume:

  1. getDefaultCommitContent will also extract gitmoji from the commit message.
  2. All information retrieved are used by getDefaultAnswers
  3. Those default answers are passed to the prompts to avoid asking the user information that we retrieved

If all those change are enough to include this feature I will to make them next week. If you judge the logic too complex (and it is) to be integrated in the project I completely understand and will pass.

Thanks you for your time reviewing it 🙏

@carloscuesta
Copy link
Owner

carloscuesta commented Feb 8, 2021

I think I've got an idea to simplify the implementation of this! 😊

Taking a look at the Inquirer.js docs you can see there's a when option that could be configured for every prompt. What this property does?

when: (Function, Boolean) Receive the current user answers hash and should return true or false depending on whether or not this question should be asked. The value can also be a simple boolean.

So basically, what we can try, is to add the when property to the title and message prompts conditionally based on the configurationVault option. Something like:

{
      name: 'title',
      message: 'Enter the commit title',
      validate: guard.title,
      transformer: (input: string) => {
        return `[${
          (title || input).length
        }/${TITLE_MAX_LENGTH_COUNT}]: ${input}`
      },
      ...(title ? { default: title } : {}),
      ...(configurationVault.skipOption ? { when: true } : {})
    },
    {
      name: 'message',
      message: 'Enter the commit message:',
      validate: guard.message,
      ...(message ? { default: message } : {}),
      ...(configurationVault.skipOption ? { when: true } : {})
    }

Then we can unify all the prompts logic inside of prompts.js

What do you think?

@momsse
Copy link
Author

momsse commented Feb 8, 2021

Hi @carloscuesta,

Thanks for the suggestion. This can simplify the prompt a little bit (we do not need to read defaultAnswers). Unfortunately when we use this option { when: false } the question is skipped but the default answer too :/ This is not a solution that can help us removing getDefaultAnswers function.

Tell me if I missed the point. Here the changes I tried:

export default (
  gitmojis: Array<Gitmoji>,
  { gitmoji, title, message }: CommitContent
): Array<Object> => {
  const skipPromptingFilledInfo = configurationVault.getSkipPromptingFilledInfo()

  return [
    {
      name: 'gitmoji',
      message: 'Choose a gitmoji:',
      type: 'autocomplete',
      source: (answersSoFor: any, input: string) => {
        return Promise.resolve(
          filterGitmojis(input, gitmojis).map((gitmoji) => ({
            name: `${gitmoji.emoji}  - ${gitmoji.description}`,
            value: gitmoji[configurationVault.getEmojiFormat()]
          }))
        )
      },
      ...(gitmoji ? { default: gitmoji } : {}),
      ...(skipPromptingFilledInfo && gitmoji ? { when: false } : {}),
    },
    {
      name: 'scope',
      message: 'Enter the scope of current changes:',
      validate: guard.scope,
      ...(!configurationVault.getScopePrompt() ? { when: false } : {}),
    },
    {
      name: 'title',
      message: 'Enter the commit title',
      validate: guard.title,
      transformer: (input: string) => {
        return `[${
          (title || input).length
        }/${TITLE_MAX_LENGTH_COUNT}]: ${input}`
      },
      ...(title ? { default: title } : {}),
      ...(skipPromptingFilledInfo && title && guard.title(title) ? { when: false } : {}),
    },
    {
      name: 'message',
      message: 'Enter the commit message:',
      validate: guard.message,
      ...(message ? { default: message } : {}),
      ...(skipPromptingFilledInfo && message && guard.message(message) ? { when: false } : {}),
    }
  ]
}

@carloscuesta
Copy link
Owner

Will take a look at this shortly!

@carloscuesta
Copy link
Owner

Hey @momsse sorry for the delay!

Since we don't have a simple way to introduce this feature at the moment, I think it would be great to skip at this moment (because it's not a big deal for the UX of the cli). Hope we can revisit this on a future iteration and opportunity

Thanks for the time and effort you put on this PR, I really appreciate it, thanks ❤️

@Karsens
Copy link

Karsens commented Dec 12, 2021

Hi, I saw that this wasn't merged. Very unfortunate because I really need this as I usually don't put so much effort into my git commits and would really like them fast. So I won't use gitmoji for now. :( Hope you can merge this in the future!

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 9, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants