Skip to content

Commit

Permalink
feat: add skipQuestions config to skip some questions
Browse files Browse the repository at this point in the history
  • Loading branch information
dengyongchi committed Mar 8, 2024
1 parent a93bd96 commit 31d98c2
Show file tree
Hide file tree
Showing 2 changed files with 124 additions and 122 deletions.
243 changes: 122 additions & 121 deletions engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,127 @@ module.exports = function(options) {
value: key
};
});
const initQuestions = [
{
type: 'list',
name: 'type',
message: "Select the type of change that you're committing:",
choices: choices,
default: options.defaultType
},
{
type: 'input',
name: 'scope',
message:
'What is the scope of this change (e.g. component or file name): (press enter to skip)',
default: options.defaultScope,
filter: function(value) {
return options.disableScopeLowerCase
? value.trim()
: value.trim().toLowerCase();
}
},
{
type: 'input',
name: 'subject',
message: function(answers) {
return (
'Write a short, imperative tense description of the change (max ' +
maxSummaryLength(options, answers) +
' chars):\n'
);
},
default: options.defaultSubject,
validate: function(subject, answers) {
var filteredSubject = filterSubject(subject, options.disableSubjectLowerCase);
return filteredSubject.length == 0
? 'subject is required'
: filteredSubject.length <= maxSummaryLength(options, answers)
? true
: 'Subject length must be less than or equal to ' +
maxSummaryLength(options, answers) +
' characters. Current length is ' +
filteredSubject.length +
' characters.';
},
transformer: function(subject, answers) {
var filteredSubject = filterSubject(subject, options.disableSubjectLowerCase);
var color =
filteredSubject.length <= maxSummaryLength(options, answers)
? chalk.green
: chalk.red;
return color('(' + filteredSubject.length + ') ' + subject);
},
filter: function(subject) {
return filterSubject(subject, options.disableSubjectLowerCase);
}
},
{
type: 'input',
name: 'body',
message:
'Provide a longer description of the change: (press enter to skip)\n',
default: options.defaultBody
},
{
type: 'confirm',
name: 'isBreaking',
message: 'Are there any breaking changes?',
default: false
},
{
type: 'input',
name: 'breakingBody',
default: '-',
message:
'A BREAKING CHANGE commit requires a body. Please enter a longer description of the commit itself:\n',
when: function(answers) {
return answers.isBreaking && !answers.body;
},
validate: function(breakingBody, answers) {
return (
breakingBody.trim().length > 0 ||
'Body is required for BREAKING CHANGE'
);
}
},
{
type: 'input',
name: 'breaking',
message: 'Describe the breaking changes:\n',
when: function(answers) {
return answers.isBreaking;
}
},

{
type: 'confirm',
name: 'isIssueAffected',
message: 'Does this change affect any open issues?',
default: options.defaultIssues ? true : false
},
{
type: 'input',
name: 'issuesBody',
default: '-',
message:
'If issues are closed, the commit requires a body. Please enter a longer description of the commit itself:\n',
when: function(answers) {
return (
answers.isIssueAffected && !answers.body && !answers.breakingBody
);
}
},
{
type: 'input',
name: 'issues',
message: 'Add issue references (e.g. "fix #123", "re #123".):\n',
when: function(answers) {
return answers.isIssueAffected;
},
default: options.defaultIssues ? options.defaultIssues : undefined
}
];
return {
// When a user runs `git cz`, prompter will
// be executed. We pass you cz, which currently
Expand All @@ -67,127 +187,8 @@ module.exports = function(options) {
// See inquirer.js docs for specifics.
// You can also opt to use another input
// collection library if you prefer.
cz.prompt([
{
type: 'list',
name: 'type',
message: "Select the type of change that you're committing:",
choices: choices,
default: options.defaultType
},
{
type: 'input',
name: 'scope',
message:
'What is the scope of this change (e.g. component or file name): (press enter to skip)',
default: options.defaultScope,
filter: function(value) {
return options.disableScopeLowerCase
? value.trim()
: value.trim().toLowerCase();
}
},
{
type: 'input',
name: 'subject',
message: function(answers) {
return (
'Write a short, imperative tense description of the change (max ' +
maxSummaryLength(options, answers) +
' chars):\n'
);
},
default: options.defaultSubject,
validate: function(subject, answers) {
var filteredSubject = filterSubject(subject, options.disableSubjectLowerCase);
return filteredSubject.length == 0
? 'subject is required'
: filteredSubject.length <= maxSummaryLength(options, answers)
? true
: 'Subject length must be less than or equal to ' +
maxSummaryLength(options, answers) +
' characters. Current length is ' +
filteredSubject.length +
' characters.';
},
transformer: function(subject, answers) {
var filteredSubject = filterSubject(subject, options.disableSubjectLowerCase);
var color =
filteredSubject.length <= maxSummaryLength(options, answers)
? chalk.green
: chalk.red;
return color('(' + filteredSubject.length + ') ' + subject);
},
filter: function(subject) {
return filterSubject(subject, options.disableSubjectLowerCase);
}
},
{
type: 'input',
name: 'body',
message:
'Provide a longer description of the change: (press enter to skip)\n',
default: options.defaultBody
},
{
type: 'confirm',
name: 'isBreaking',
message: 'Are there any breaking changes?',
default: false
},
{
type: 'input',
name: 'breakingBody',
default: '-',
message:
'A BREAKING CHANGE commit requires a body. Please enter a longer description of the commit itself:\n',
when: function(answers) {
return answers.isBreaking && !answers.body;
},
validate: function(breakingBody, answers) {
return (
breakingBody.trim().length > 0 ||
'Body is required for BREAKING CHANGE'
);
}
},
{
type: 'input',
name: 'breaking',
message: 'Describe the breaking changes:\n',
when: function(answers) {
return answers.isBreaking;
}
},

{
type: 'confirm',
name: 'isIssueAffected',
message: 'Does this change affect any open issues?',
default: options.defaultIssues ? true : false
},
{
type: 'input',
name: 'issuesBody',
default: '-',
message:
'If issues are closed, the commit requires a body. Please enter a longer description of the commit itself:\n',
when: function(answers) {
return (
answers.isIssueAffected && !answers.body && !answers.breakingBody
);
}
},
{
type: 'input',
name: 'issues',
message: 'Add issue references (e.g. "fix #123", "re #123".):\n',
when: function(answers) {
return answers.isIssueAffected;
},
default: options.defaultIssues ? options.defaultIssues : undefined
}
]).then(function(answers) {
const finalQuestions = options.skipQuestions ? initQuestions.filter(item => !options.skipQuestions.includes(item.name)) : initQuestions;
cz.prompt(finalQuestions).then(function(answers) {
var wrapOptions = {
trim: true,
cut: false,
Expand Down
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ var options = {
(process.env.CZ_MAX_LINE_WIDTH &&
parseInt(process.env.CZ_MAX_LINE_WIDTH)) ||
config.maxLineWidth ||
100
100,
skipQuestions: process.env.CZ_SKIP_QUESTIONS || config.skipQuestions
};

(function(options) {
Expand Down

0 comments on commit 31d98c2

Please sign in to comment.