-
-
Notifications
You must be signed in to change notification settings - Fork 207
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
Conversation
6555b50
to
d0e0c8a
Compare
Codecov Report
@@ 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
Continue to review full report at Codecov.
|
There was a problem hiding this 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) { |
There was a problem hiding this comment.
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 🙏🏼
There was a problem hiding this comment.
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', |
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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' |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 ?
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 | ||
} |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 ?
const gitmojiSymbolRegex = /^(\p{Emoji_Presentation})\s*(.*)/gu | ||
const gitmojiCodeRegex = /^(:[a-zA-Z_]+:)\s*(.*)/gu |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
import getDefaultCommitContent from '../../utils/getDefaultCommitContent' | ||
import { type CommitMode } from './index' |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
const commitContent = getDefaultCommitContent(mode) | ||
const defaultAnswers = getDefaultAnswers(commitContent) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same answer as above.
To resume:
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 🙏 |
I think I've got an idea to simplify the implementation of this! 😊 Taking a look at the
So basically, what we can try, is to add the {
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 What do you think? |
Hi @carloscuesta, Thanks for the suggestion. This can simplify the prompt a little bit (we do not need to read 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 } : {}),
}
]
} |
Will take a look at this shortly! |
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 ❤️ |
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! |
Description
Add support to an option that will skip asking
gitmoji
/title
/message
when they are filled.Issue: #534
Tests