Skip to content

Commit 7b08c70

Browse files
authored
feat(additionalQuestion): support additional questions for commit (#243)
1 parent 987ace4 commit 7b08c70

3 files changed

Lines changed: 25 additions & 1 deletion

File tree

README.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,23 @@ Here are the options you can set in your `.cz-config.js`:
146146
]
147147
}
148148
```
149+
* **additionalQuestions**:{Array of object} To ask additional question. Answers will be appended to body part. All keys of object are required.
150+
```
151+
additionalQuestions: [
152+
{
153+
type: 'input',
154+
name: 'time',
155+
message: 'Time spent (i.e. 1h 15m) (optional):\n',
156+
mapping: "#time"
157+
},
158+
{
159+
type: 'input',
160+
name: 'comment',
161+
message: 'Jira comment (optional):\n',
162+
mapping: "#comment"
163+
}
164+
],
165+
```
149166
* **allowCustomScopes**: {boolean, default false}: adds the option `custom` to scope selection so you can still type a scope if you need.
150167
* **allowBreakingChanges**: {Array of Strings: default none}. List of commit types you would like to the question `breaking change` prompted. Eg.: ['feat', 'fix'].
151168
* **skipQuestions**: {Array of Strings: default none}. List of questions you want to skip. Eg.: ['body', 'footer'].
@@ -201,4 +218,4 @@ my items are:
201218

202219

203220

204-
Leonardo Correa
221+
Leonardo Correa

lib/build-commit.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,12 @@ module.exports = (answers, config) => {
9898
body = '';
9999
}
100100

101+
(config.additionalQuestions || []).forEach((question) => {
102+
if (answers[question.name]) {
103+
body += `\n${question.mapping} ${answers[question.name]}`;
104+
}
105+
});
106+
101107
const breaking = wrap(answers.breaking, wrapOptions);
102108
const footer = wrap(answers.footer, wrapOptions);
103109

lib/questions.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ module.exports = {
160160
message: messages.body,
161161
default: config.usePreparedCommit && getPreparedCommit('body'),
162162
},
163+
...(config.additionalQuestions || []),
163164
{
164165
type: 'input',
165166
name: 'breaking',

0 commit comments

Comments
 (0)