From 7b08c708180e60d2b4fe982e6e87039246df027c Mon Sep 17 00:00:00 2001 From: Parveen Kumar Date: Mon, 23 Dec 2024 13:04:05 +0530 Subject: [PATCH] feat(additionalQuestion): support additional questions for commit (#243) --- README.md | 19 ++++++++++++++++++- lib/build-commit.js | 6 ++++++ lib/questions.js | 1 + 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9b2a7e2..bd41f21 100644 --- a/README.md +++ b/README.md @@ -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']. @@ -201,4 +218,4 @@ my items are: -Leonardo Correa +Leonardo Correa \ No newline at end of file diff --git a/lib/build-commit.js b/lib/build-commit.js index 5cd4d5f..acb2c89 100644 --- a/lib/build-commit.js +++ b/lib/build-commit.js @@ -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); diff --git a/lib/questions.js b/lib/questions.js index 2d9253c..6f37093 100644 --- a/lib/questions.js +++ b/lib/questions.js @@ -160,6 +160,7 @@ module.exports = { message: messages.body, default: config.usePreparedCommit && getPreparedCommit('body'), }, + ...(config.additionalQuestions || []), { type: 'input', name: 'breaking',