conventional-changelog / conventional-changelog/commitlint

cz commitlint CLI question customization for custom rules.

Open
#2,684 8 comments 6 reactions 0 assignees View on GitHub
feature
Dominant language
TypeScript
Stars
18.7k
Forks
970
Avg merge
7h 33m
Merged PRs (30d)
49

Description

I would like to add the ability to add a CLI prompt for a custom rule. (e.g. ticket number included in commit message)

## Expected Behavior
Would like for a way to add new custom option to add ticket number to the CLI prompt.
`feat(button): added theme settings [TICKET-123]`
commitlint.config.js
```js
module.exports = {
extends: ['@commitlint/config-conventional'],
plugins: [
{
rules: {
ticket: ({ subject }) => {
const ticketRegex = /(\w+-{1}\d+)/;
return [
ticketRegex.test(subject),
"Your subject should include the ticket, for example PRJ-300.",
];
},
},
},
],
rules: {
ticket: [2, "always"],
},
parserPreset: './parser-presets.js',
prompt: {
questions: {
// ...
subject: {
description: 'Write a short, imperative tense description of the change',
},
ticket: {
description: 'Provide a Ticket Number',
},
body: {
description: 'Provide a longer description of the change',
},
// ...
},
}
}

```

parser-preset.js
```js
module.exports = {
parserOpts: {
headerPattern: /^(\w+)\(\w+\):[ ]{1}(\w{1}.+\w{1})[ ]{1}\[(\w+-{1}\d+)\]$/,
headerCorrespondence: ['type', 'scope', 'subject', 'ticket'],
},
};
```
## Current Behavior

Currently ignores my new rule / custom CLI prompt. I can't find any documentation that directly walks through this process of making a custom prompt with a custom rule. You can override current rules and change language. But unable to have question use new custom made rules. If this isn't something that can be / is supported that's perfectly fine! I'm just curious if it's currently possible, and if it is where I may be tripping up.

## Affected packages
- [X] cli
- [X] cz-commitlint

| Executable | Version |
| ---------------------: | :------ |
| `commitlint --version` | 12.1.4 |
| `git --version` | 2.32.0|
| `node --version` | 14.17.1 |

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.