Skip to content

Commit e5e4d29

Browse files
committed
feat: adds "ticketNumberSuffix" and "ticketNumberPosition" config options
1 parent 51cab09 commit e5e4d29

File tree

4 files changed

+107
-11
lines changed

4 files changed

+107
-11
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ Here are the options you can set in your `.cz-config.js`:
125125
* **skipQuestions**: {Array of Strings: default none}. List of questions you want to skip. Eg.: ['body', 'footer'].
126126
* **appendBranchNameToCommitMessage**: If you use `cz-customizable` with `cz-customizable-ghooks`, you can get the branch name automatically appended to the commit message. This is done by a commit hook on `cz-customizable-ghooks`. This option has been added on `cz-customizable-ghooks`, v1.3.0. Default value is `true`.
127127
* **ticketNumberPrefix**: {string, default 'ISSUES CLOSED:'}: Set custom prefix for footer ticker number.
128+
* **ticketNumberSuffix**: {string, default ' '}: Set custom prefix for footer ticker number.
129+
* **ticketNumberPosition**: {string <small>[ 'first', 'standard' or 'last' ]</small>, default none}: Set custom placement for footer ticker number.
128130
* **breakingPrefix**: {string, default 'BREAKING CHANGE:'}: Set a custom prefix for the breaking change block in commit messages.
129131
* **footerPrefix**: {string, default 'ISSUES CLOSED:'}: Set a custom prefix for the footer block in commit messages. Set to empty string to remove prefix.
130132
* **breaklineChar**: {string, default '|'}: It gets replaced with \n to create the breakline in your commit message. This is supported for fields `body` and `footer` at the moment.

buildCommit.js

Lines changed: 46 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,25 @@ const defaultMaxLineWidth = 100;
66
const defaultBreaklineChar = '|';
77

88
const addTicketNumber = (ticketNumber, config) => {
9+
let result;
10+
911
if (!ticketNumber) {
1012
return '';
1113
}
14+
15+
result = ticketNumber.trim();
16+
1217
if (config.ticketNumberPrefix) {
13-
return `${config.ticketNumberPrefix + ticketNumber.trim()} `;
18+
result = `${config.ticketNumberPrefix}${result}`;
19+
}
20+
21+
if (config.ticketNumberSuffix || config.ticketNumberSuffix === '') {
22+
result = `${result}${config.ticketNumberSuffix}`;
23+
} else {
24+
result = `${result} `;
1425
}
15-
return `${ticketNumber.trim()} `;
26+
27+
return result;
1628
};
1729

1830
const addScope = (scope, config) => {
@@ -67,15 +79,38 @@ module.exports = (answers, config) => {
6779
indent: '',
6880
width: defaultMaxLineWidth,
6981
};
70-
71-
// Hard limit this line
72-
// eslint-disable-next-line max-len
73-
const head = (
74-
addType(answers.type, config) +
75-
addScope(answers.scope, config) +
76-
addTicketNumber(answers.ticketNumber, config) +
77-
addSubject(answers.subject)
78-
).slice(0, defaultMaxLineWidth);
82+
let head;
83+
84+
switch (config.ticketNumberPosition) {
85+
case 'first':
86+
// Hard limit this line
87+
head = (
88+
addTicketNumber(answers.ticketNumber, config) +
89+
addType(answers.type, config) +
90+
addScope(answers.scope, config) +
91+
addSubject(answers.subject)
92+
).slice(0, defaultMaxLineWidth);
93+
break;
94+
case 'last':
95+
// Hard limit this line
96+
head = (
97+
addType(answers.type, config) +
98+
addScope(answers.scope, config) +
99+
addSubject(answers.subject) +
100+
addTicketNumber(answers.ticketNumber, config)
101+
).slice(0, defaultMaxLineWidth);
102+
break;
103+
case 'standard':
104+
default:
105+
// Hard limit this line
106+
head = (
107+
addType(answers.type, config) +
108+
addScope(answers.scope, config) +
109+
addTicketNumber(answers.ticketNumber, config) +
110+
addSubject(answers.subject)
111+
).slice(0, defaultMaxLineWidth);
112+
break;
113+
}
79114

80115
// Wrap these lines at 100 characters
81116
let body = wrap(answers.body, wrapOptions) || '';

index.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ declare module "cz-customizable" {
2222
skipQuestions?: string[];
2323
appendBranchNameToCommitMessage?: boolean;
2424
ticketNumberPrefix?: string;
25+
ticketNumberSuffix?: string;
26+
ticketNumberPosition?: string;
2527
breakingPrefix?: string;
2628
footerPrefix?: string;
2729
subjectLimit?: number;

spec/buildCommitSpec.js

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,4 +98,61 @@ line 2`;
9898
expect(buildCommit(answersNoScope, options)).toEqual(expecteMessage);
9999
});
100100
});
101+
102+
describe('with ticketNumberSuffix', () => {
103+
it('should be visible', () => {
104+
const answersTicketNumberSuffix = {
105+
...answers,
106+
ticketNumber: '12345',
107+
};
108+
const options = {
109+
allowTicketNumber: true,
110+
ticketNumberSuffix: '@@@ ',
111+
};
112+
113+
expect(buildCommit(answersTicketNumberSuffix, options)).toEqual('feat(app): 12345@@@ this is a new feature');
114+
});
115+
});
116+
117+
describe('with ticketNumberPosition', () => {
118+
it('should be same', () => {
119+
const answersTicketNumberSuffix = {
120+
...answers,
121+
ticketNumber: '12345',
122+
};
123+
const options = {
124+
allowTicketNumber: true,
125+
ticketNumberPosition: 'standard',
126+
};
127+
128+
expect(buildCommit(answersTicketNumberSuffix, options)).toEqual('feat(app): 12345 this is a new feature');
129+
});
130+
131+
it('should be "first"', () => {
132+
const answersTicketNumberSuffix = {
133+
...answers,
134+
ticketNumber: '12345',
135+
};
136+
const options = {
137+
allowTicketNumber: true,
138+
ticketNumberPosition: 'first',
139+
};
140+
141+
expect(buildCommit(answersTicketNumberSuffix, options)).toEqual('12345 feat(app): this is a new feature');
142+
});
143+
144+
it('should be "last"', () => {
145+
const answersTicketNumberSuffix = {
146+
...answers,
147+
ticketNumber: '12345',
148+
};
149+
const options = {
150+
allowTicketNumber: true,
151+
ticketNumberSuffix: '',
152+
ticketNumberPosition: 'last',
153+
};
154+
155+
expect(buildCommit(answersTicketNumberSuffix, options)).toEqual('feat(app): this is a new feature12345');
156+
});
157+
});
101158
});

0 commit comments

Comments
 (0)