Skip to content

Commit

Permalink
feat(additionalQuestion): support additional questions for commit
Browse files Browse the repository at this point in the history
  • Loading branch information
parveen14 committed Dec 9, 2024
1 parent ba73eb3 commit 5028a05
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 1 deletion.
19 changes: 18 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,23 @@ Here are the options you can set in your `.cz-config.js`:
]
}
```
* **additionalQuestions**:{Array of object} To ask additional question. Answers will be appended to body part. All keys of object are required.
```
additionalQuestions: [
{
type: 'input',
name: 'time',
message: 'Time spent (i.e. 1h 15m) (optional):\n',
mapping: "#time"
},
{
type: 'input',
name: 'comment',
message: 'Jira comment (optional):\n',
mapping: "#comment"
}
],
```
* **allowCustomScopes**: {boolean, default false}: adds the option `custom` to scope selection so you can still type a scope if you need.
* **allowBreakingChanges**: {Array of Strings: default none}. List of commit types you would like to the question `breaking change` prompted. Eg.: ['feat', 'fix'].
* **skipQuestions**: {Array of Strings: default none}. List of questions you want to skip. Eg.: ['body', 'footer'].
Expand Down Expand Up @@ -201,4 +218,4 @@ my items are:



Leonardo Correa
Leonardo Correa
15 changes: 15 additions & 0 deletions cz-config-EXAMPLE.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,21 @@ module.exports = {
{ value: 'WIP', name: 'WIP: Work in progress' },
],

additionalQuestions: [
{
type: 'input',
name: 'time',
message: 'Time spent (i.e. 1h 15m) (optional):\n',
mapping: '#time',
},
{
type: 'input',
name: 'comment',
message: 'Jira comment (optional):\n',
mapping: '#comment',
},
],

scopes: [{ name: 'accounts' }, { name: 'admin' }, { name: 'exampleScope' }, { name: 'changeMe' }],

usePreparedCommit: false, // to re-use commit from ./.git/COMMIT_EDITMSG
Expand Down
6 changes: 6 additions & 0 deletions lib/build-commit.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ module.exports = (answers, config) => {
body = '';
}

(config.additionalQuestions || []).forEach((question) => {
if (answers[question.name]) {
body += `\n${question.mapping} ${answers[question.name]}`;
}
});

const breaking = wrap(answers.breaking, wrapOptions);
const footer = wrap(answers.footer, wrapOptions);

Expand Down
1 change: 1 addition & 0 deletions lib/questions.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ module.exports = {
message: messages.body,
default: config.usePreparedCommit && getPreparedCommit('body'),
},
...(config.additionalQuestions || []),
{
type: 'input',
name: 'breaking',
Expand Down

0 comments on commit 5028a05

Please sign in to comment.