Reputation: 330
I am using commit lint and I want to use conventional commits but i want to include a Jira Ticket.
Example TEST-23: fix: my body
Upvotes: 3
Views: 1442
Reputation: 11
maybe this will solve it:
import type { UserConfig } from '@commitlint/types';
const Configuration: UserConfig = {
extends: ['@commitlint/config-conventional'],
rules: {
'type-empty': [0],
'subject-empty': [0],
'task-type-pattern': [2, 'always']
},
plugins: [
{
rules: {
'task-type-pattern': ({ header }) => {
const regex = /^TEST-\d+: (feat|fix|perf|style|docs|test|refactor|build|ci|chore|revert|wip|workflow): .+/;
if (!header || !regex.test(header)) {
return [
false,
'Commit message must be in the format: <TASK-NUMBER>: <TYPE>: <MESSAGE> (e.g., TEST-23: fix: my body)',
];
}
return [true];
},
},
},
],
};
export default Configuration;
Upvotes: 0
Reputation: 330
In my case I needed to create a custom parser and a plugin with a custom rule.
const jiraTicketRegex = /^[A-Z]+-\d+$/;
module.exports = {
extends: ['@commitlint/config-conventional'],
rules: {
'subject-case': [2, 'always', 'sentence-case'],
'header-max-length': [2, 'always', 100],
'jira-ticket-format': [2, 'always'],
},
parserPreset: {
parserOpts: {
headerPattern: /^([A-Z]+-\d+)\s*:\s*(\w*): (.*)$/,
headerCorrespondence: ['ticket', 'type', 'subject'],
},
},
plugins: [
{
rules: {
'jira-ticket-format': (parsed) => {
const ticket = parsed.ticket;
if (!jiraTicketRegex.test(ticket)) {
return [
false,
`Wrong format".`,
];
}
return [true];
},
},
},
],
};
Upvotes: 0