Skip to content

Commit dc6ff87

Browse files
committed
feat(additionalQuestion): support additional questions for commit
1 parent ba73eb3 commit dc6ff87

File tree

4 files changed

+41
-1
lines changed

4 files changed

+41
-1
lines changed

README.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,24 @@ 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+
```
166+
149167
* **allowCustomScopes**: {boolean, default false}: adds the option `custom` to scope selection so you can still type a scope if you need.
150168
* **allowBreakingChanges**: {Array of Strings: default none}. List of commit types you would like to the question `breaking change` prompted. Eg.: ['feat', 'fix'].
151169
* **skipQuestions**: {Array of Strings: default none}. List of questions you want to skip. Eg.: ['body', 'footer'].
@@ -201,4 +219,4 @@ my items are:
201219

202220

203221

204-
Leonardo Correa
222+
Leonardo Correa

cz-config-EXAMPLE.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,21 @@ module.exports = {
2424
{ value: 'WIP', name: 'WIP: Work in progress' },
2525
],
2626

27+
additionalQuestions: [
28+
{
29+
type: 'input',
30+
name: 'time',
31+
message: 'Time spent (i.e. 1h 15m) (optional):\n',
32+
mapping: '#time',
33+
},
34+
{
35+
type: 'input',
36+
name: 'comment',
37+
message: 'Jira comment (optional):\n',
38+
mapping: '#comment',
39+
},
40+
],
41+
2742
scopes: [{ name: 'accounts' }, { name: 'admin' }, { name: 'exampleScope' }, { name: 'changeMe' }],
2843

2944
usePreparedCommit: false, // to re-use commit from ./.git/COMMIT_EDITMSG

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)