Skip to content

Commit

Permalink
✨ Feat: Display warning if commit message is too long
Browse files Browse the repository at this point in the history
  • Loading branch information
dani-sc committed Mar 16, 2017
1 parent 0cfbe4e commit 7789b7a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
15 changes: 13 additions & 2 deletions lib/cli.js
Expand Up @@ -9,8 +9,19 @@ const configuration = getConfig();
const choicesList = choices(configuration);
const questionsList = questions(choicesList);

inquirer.prompt(questionsList).then((answers) => {
const message = answers.moreInfo ? `${answers.editor}` : `${answers.type} ${answers.description}`;
const prompt = inquirer.prompt(questionsList);

prompt.ui.process.subscribe((answer) => {
if (answer.name === 'commitMessageWarning') {
const continueExecution = answer.answer;
if (!continueExecution) {
process.exit();
}
}
});

prompt.then((answers) => {
const message = answers.moreInfo ? `${answers.editor}` : `${answers.type} ${answers.commitMessage}`;

return execa('git', ['commit', '-m', message])
.then(result => console.log(result.stdout))
Expand Down
10 changes: 8 additions & 2 deletions lib/promptConfig.js
Expand Up @@ -27,10 +27,16 @@ const questions = (choicesList) => {
},
{
type: 'input',
name: 'description',
name: 'commitMessage',
message: 'Enter your commit message:',
validate: input => (input ? true : 'A commit message is mandatory!'),
},
{
type: 'confirm',
when: answers => answers.commitMessage.length > 50,
name: 'commitMessageWarning',
message: chalk.yellow('A maximum commit message length of 50 is recommended! Do you want to continue anyway?'),
},
{
type: 'confirm',
name: 'moreInfo',
Expand All @@ -42,7 +48,7 @@ const questions = (choicesList) => {
name: 'editor',
message: 'This will let you add more information',
when: answers => answers.moreInfo,
default: answers => `${answers.type} ${answers.description}\n\n\n`,
default: answers => `${answers.type} ${answers.commitMessage}\n\n\n`,
},
];

Expand Down

0 comments on commit 7789b7a

Please sign in to comment.