Skip to content

Commit 17c7fdf

Browse files
authoredDec 12, 2022
feat: add skipType option (#75)
closes #74
1 parent 799fc9c commit 17c7fdf

File tree

5 files changed

+338
-47
lines changed

5 files changed

+338
-47
lines changed
 

‎README.md

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ Like commitizen, you can specify the configuration of cz-conventional-changelog-
5252
| CZ_MIN_HEADER_WIDTH | minHeaderWidth | 2 | This limits how short a commit message can be. |
5353
| CZ_MAX_LINE_WIDTH | maxLineWidth | 100 | Commit message bodies are automatically wrapped. This decides how long the lines will be. |
5454
| CZ_SKIP_SCOPE | skipScope | true | If scope should be used in commit messages. |
55+
| CZ_SKIP_TYPE | skipType | false | If type should be used in commit messages. |
5556
| CZ_SKIP_DESCRIPTION | skipDescription | false | If description should be used in commit messages. |
5657
| CZ_SKIP_BREAKING | skipBreaking | false | If breaking changes should be used in commit messages. |
5758
| | scopes | undefined | A list (JS Array) of scopes that will be available for selection. Note that adding this will change the scope field from Inquirer 'input' to 'list'. |

‎defaults.js

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ module.exports = {
44
types: conventionalCommitTypes,
55
jiraMode: true,
66
skipScope: true,
7+
skipType: false,
78
skipDescription: false,
89
skipBreaking: false,
910
customScope: false,

‎engine.js

+19-8
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,32 @@ module.exports = function(options) {
3131
var getFromOptionsOrDefaults = function(key) {
3232
return options[key] || defaults[key];
3333
};
34-
var getJiraIssueLocation = function(location, type, scope, jiraWithDecorators, subject) {
35-
switch(location) {
34+
var getJiraIssueLocation = function(
35+
location,
36+
type = '',
37+
scope = '',
38+
jiraWithDecorators,
39+
subject
40+
) {
41+
let headerPrefix = type + scope;
42+
if (headerPrefix !== '') {
43+
headerPrefix += ': ';
44+
}
45+
switch (location) {
3646
case 'pre-type':
37-
return jiraWithDecorators + type + scope + ': ' + subject;
47+
return jiraWithDecorators + headerPrefix + subject;
3848
break;
3949
case 'pre-description':
40-
return type + scope + ': ' + jiraWithDecorators + subject;
50+
return headerPrefix + jiraWithDecorators + subject;
4151
break;
4252
case 'post-description':
43-
return type + scope + ': ' + subject + ' ' + jiraWithDecorators;
53+
return headerPrefix + subject + ' ' + jiraWithDecorators;
4454
break;
4555
case 'post-body':
46-
return type + scope + ': ' + subject;
56+
return headerPrefix + subject;
4757
break;
4858
default:
49-
return type + scope + ': ' + jiraWithDecorators + subject;
59+
return headerPrefix + jiraWithDecorators + subject;
5060
}
5161
};
5262

@@ -112,9 +122,10 @@ module.exports = function(options) {
112122
{
113123
type: 'list',
114124
name: 'type',
125+
when: !options.skipType,
115126
message: "Select the type of change that you're committing:",
116127
choices: choices,
117-
default: options.defaultType
128+
default: options.skipType ? '' : options.defaultType
118129
},
119130
{
120131
type: 'input',

‎engine.test.js

+312-39
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ var expect = chai.expect;
1111
chai.should();
1212

1313
var defaultOptions = defaults;
14+
const skipTypeOptions = {
15+
...defaultOptions,
16+
skipType: true
17+
};
1418

1519
var type = 'func';
1620
var scope = 'everything';
@@ -49,7 +53,18 @@ var longIssuesSplit =
4953
longIssues.slice(defaultOptions.maxLineWidth * 2, longIssues.length).trim();
5054

5155
describe('commit message', function() {
52-
it('only header w/ out scope', function() {
56+
it('only header w/ out scope and w/ out type', function() {
57+
expect(
58+
commitMessage(
59+
{
60+
jira,
61+
subject
62+
},
63+
skipTypeOptions
64+
)
65+
).to.equal(`${jiraUpperCase} ${subject}`);
66+
});
67+
it('only header w/ out scope and w/ type', function() {
5368
expect(
5469
commitMessage({
5570
type,
@@ -58,7 +73,7 @@ describe('commit message', function() {
5873
})
5974
).to.equal(`${type}: ${jiraUpperCase} ${subject}`);
6075
});
61-
it('only header w/ scope', function() {
76+
it('only header w/ scope and w/ type', function() {
6277
expect(
6378
commitMessage({
6479
type,
@@ -68,7 +83,19 @@ describe('commit message', function() {
6883
})
6984
).to.equal(`${type}(${scope}): ${jiraUpperCase} ${subject}`);
7085
});
71-
it('header and body w/ out scope', function() {
86+
it('only header w/ scope and w/ out type', function() {
87+
expect(
88+
commitMessage(
89+
{
90+
scope,
91+
jira,
92+
subject
93+
},
94+
skipTypeOptions
95+
)
96+
).to.equal(`(${scope}): ${jiraUpperCase} ${subject}`);
97+
});
98+
it('header and body w/ out scope and w/ type', function() {
7299
expect(
73100
commitMessage({
74101
type,
@@ -78,7 +105,19 @@ describe('commit message', function() {
78105
})
79106
).to.equal(`${type}: ${jiraUpperCase} ${subject}\n\n${body}`);
80107
});
81-
it('header and body w/ scope', function() {
108+
it('header and body w/ out scope and w/ out type', function() {
109+
expect(
110+
commitMessage(
111+
{
112+
jira,
113+
subject,
114+
body
115+
},
116+
skipTypeOptions
117+
)
118+
).to.equal(`${jiraUpperCase} ${subject}\n\n${body}`);
119+
});
120+
it('header and body w/ scope and w/ type', function() {
82121
expect(
83122
commitMessage({
84123
type,
@@ -89,6 +128,19 @@ describe('commit message', function() {
89128
})
90129
).to.equal(`${type}(${scope}): ${jiraUpperCase} ${subject}\n\n${body}`);
91130
});
131+
it('header and body w/ scope and w/ out type', function() {
132+
expect(
133+
commitMessage(
134+
{
135+
scope,
136+
jira,
137+
subject,
138+
body
139+
},
140+
skipTypeOptions
141+
)
142+
).to.equal(`(${scope}): ${jiraUpperCase} ${subject}\n\n${body}`);
143+
});
92144
it('header and body w/ custom scope', function() {
93145
expect(
94146
commitMessage({
@@ -99,9 +151,24 @@ describe('commit message', function() {
99151
subject,
100152
body
101153
})
102-
).to.equal(`${type}(${customScope}): ${jiraUpperCase} ${subject}\n\n${body}`);
154+
).to.equal(
155+
`${type}(${customScope}): ${jiraUpperCase} ${subject}\n\n${body}`
156+
);
157+
});
158+
it('header, body and issues w/ out scope and w/ out type', function() {
159+
expect(
160+
commitMessage(
161+
{
162+
jira,
163+
subject,
164+
body,
165+
issues
166+
},
167+
skipTypeOptions
168+
)
169+
).to.equal(`${jiraUpperCase} ${subject}\n\n${body}\n\n${issues}`);
103170
});
104-
it('header, body and issues w/ out scope', function() {
171+
it('header, body and issues w/ out scope and w/ type', function() {
105172
expect(
106173
commitMessage({
107174
type,
@@ -112,7 +179,23 @@ describe('commit message', function() {
112179
})
113180
).to.equal(`${type}: ${jiraUpperCase} ${subject}\n\n${body}\n\n${issues}`);
114181
});
115-
it('header, body and issues w/ scope', function() {
182+
it('header, body and issues w/ scope and w/ out type', function() {
183+
expect(
184+
commitMessage(
185+
{
186+
scope,
187+
jira,
188+
subject,
189+
body,
190+
issues
191+
},
192+
skipTypeOptions
193+
)
194+
).to.equal(
195+
`(${scope}): ${jiraUpperCase} ${subject}\n\n${body}\n\n${issues}`
196+
);
197+
});
198+
it('header, body and issues w/ scope and w/ type', function() {
116199
expect(
117200
commitMessage({
118201
type,
@@ -122,9 +205,24 @@ describe('commit message', function() {
122205
body,
123206
issues
124207
})
125-
).to.equal(`${type}(${scope}): ${jiraUpperCase} ${subject}\n\n${body}\n\n${issues}`);
208+
).to.equal(
209+
`${type}(${scope}): ${jiraUpperCase} ${subject}\n\n${body}\n\n${issues}`
210+
);
211+
});
212+
it('header, body and long issues w/ out scope and w/ out type', function() {
213+
expect(
214+
commitMessage(
215+
{
216+
jira,
217+
subject,
218+
body,
219+
issues: longIssues
220+
},
221+
skipTypeOptions
222+
)
223+
).to.equal(`${jiraUpperCase} ${subject}\n\n${body}\n\n${longIssuesSplit}`);
126224
});
127-
it('header, body and long issues w/ out scope', function() {
225+
it('header, body and long issues w/ out scope and w/ type', function() {
128226
expect(
129227
commitMessage({
130228
type,
@@ -133,9 +231,27 @@ describe('commit message', function() {
133231
body,
134232
issues: longIssues
135233
})
136-
).to.equal(`${type}: ${jiraUpperCase} ${subject}\n\n${body}\n\n${longIssuesSplit}`);
234+
).to.equal(
235+
`${type}: ${jiraUpperCase} ${subject}\n\n${body}\n\n${longIssuesSplit}`
236+
);
237+
});
238+
it('header, body and long issues w/ scope and w/ out type', function() {
239+
expect(
240+
commitMessage(
241+
{
242+
scope,
243+
jira,
244+
subject,
245+
body,
246+
issues: longIssues
247+
},
248+
skipTypeOptions
249+
)
250+
).to.equal(
251+
`(${scope}): ${jiraUpperCase} ${subject}\n\n${body}\n\n${longIssuesSplit}`
252+
);
137253
});
138-
it('header, body and long issues w/ scope', function() {
254+
it('header, body and long issues w/ scope and w/ tyoe', function() {
139255
expect(
140256
commitMessage({
141257
type,
@@ -149,7 +265,19 @@ describe('commit message', function() {
149265
`${type}(${scope}): ${jiraUpperCase} ${subject}\n\n${body}\n\n${longIssuesSplit}`
150266
);
151267
});
152-
it('header and long body w/ out scope', function() {
268+
it('header and long body w/ out scope and w/ out type', function() {
269+
expect(
270+
commitMessage(
271+
{
272+
jira,
273+
subject,
274+
body: longBody
275+
},
276+
skipTypeOptions
277+
)
278+
).to.equal(`${jiraUpperCase} ${subject}\n\n${longBodySplit}`);
279+
});
280+
it('header and long body w/ out scope and w/ type', function() {
153281
expect(
154282
commitMessage({
155283
type,
@@ -159,7 +287,20 @@ describe('commit message', function() {
159287
})
160288
).to.equal(`${type}: ${jiraUpperCase} ${subject}\n\n${longBodySplit}`);
161289
});
162-
it('header and long body w/ scope', function() {
290+
it('header and long body w/ scope and w/ out type', function() {
291+
expect(
292+
commitMessage(
293+
{
294+
scope,
295+
jira,
296+
subject,
297+
body: longBody
298+
},
299+
skipTypeOptions
300+
)
301+
).to.equal(`(${scope}): ${jiraUpperCase} ${subject}\n\n${longBodySplit}`);
302+
});
303+
it('header and long body w/ scope and w/ type', function() {
163304
expect(
164305
commitMessage({
165306
type,
@@ -168,9 +309,24 @@ describe('commit message', function() {
168309
subject,
169310
body: longBody
170311
})
171-
).to.equal(`${type}(${scope}): ${jiraUpperCase} ${subject}\n\n${longBodySplit}`);
312+
).to.equal(
313+
`${type}(${scope}): ${jiraUpperCase} ${subject}\n\n${longBodySplit}`
314+
);
315+
});
316+
it('header, long body and issues w/ out scope and w/ out type', function() {
317+
expect(
318+
commitMessage(
319+
{
320+
jira,
321+
subject,
322+
body: longBody,
323+
issues
324+
},
325+
skipTypeOptions
326+
)
327+
).to.equal(`${jiraUpperCase} ${subject}\n\n${longBodySplit}\n\n${issues}`);
172328
});
173-
it('header, long body and issues w/ out scope', function() {
329+
it('header, long body and issues w/ out scope and w/ type', function() {
174330
expect(
175331
commitMessage({
176332
type,
@@ -179,9 +335,27 @@ describe('commit message', function() {
179335
body: longBody,
180336
issues
181337
})
182-
).to.equal(`${type}: ${jiraUpperCase} ${subject}\n\n${longBodySplit}\n\n${issues}`);
338+
).to.equal(
339+
`${type}: ${jiraUpperCase} ${subject}\n\n${longBodySplit}\n\n${issues}`
340+
);
183341
});
184-
it('header, long body and issues w/ scope', function() {
342+
it('header, long body and issues w/ scope and w/ out type', function() {
343+
expect(
344+
commitMessage(
345+
{
346+
scope,
347+
jira,
348+
subject,
349+
body: longBody,
350+
issues
351+
},
352+
skipTypeOptions
353+
)
354+
).to.equal(
355+
`(${scope}): ${jiraUpperCase} ${subject}\n\n${longBodySplit}\n\n${issues}`
356+
);
357+
});
358+
it('header, long body and issues w/ scope and w/ type', function() {
185359
expect(
186360
commitMessage({
187361
type,
@@ -195,7 +369,22 @@ describe('commit message', function() {
195369
`${type}(${scope}): ${jiraUpperCase} ${subject}\n\n${longBodySplit}\n\n${issues}`
196370
);
197371
});
198-
it('header, long body and long issues w/ out scope', function() {
372+
it('header, long body and long issues w/ out scope and w/ out type', function() {
373+
expect(
374+
commitMessage(
375+
{
376+
jira,
377+
subject,
378+
body: longBody,
379+
issues: longIssues
380+
},
381+
skipTypeOptions
382+
)
383+
).to.equal(
384+
`${jiraUpperCase} ${subject}\n\n${longBodySplit}\n\n${longIssuesSplit}`
385+
);
386+
});
387+
it('header, long body and long issues w/ out scope and w/ type', function() {
199388
expect(
200389
commitMessage({
201390
type,
@@ -208,7 +397,23 @@ describe('commit message', function() {
208397
`${type}: ${jiraUpperCase} ${subject}\n\n${longBodySplit}\n\n${longIssuesSplit}`
209398
);
210399
});
211-
it('header, long body and long issues w/ scope', function() {
400+
it('header, long body and long issues w/ scope and w/ out type', function() {
401+
expect(
402+
commitMessage(
403+
{
404+
scope,
405+
jira,
406+
subject,
407+
body: longBody,
408+
issues: longIssues
409+
},
410+
skipTypeOptions
411+
)
412+
).to.equal(
413+
`(${scope}): ${jiraUpperCase} ${subject}\n\n${longBodySplit}\n\n${longIssuesSplit}`
414+
);
415+
});
416+
it('header, long body and long issues w/ scope and w/ type', function() {
212417
expect(
213418
commitMessage({
214419
type,
@@ -225,7 +430,6 @@ describe('commit message', function() {
225430
it('header, long body, breaking change, and long issues w/ scope', function() {
226431
expect(
227432
commitMessage({
228-
type,
229433
scope,
230434
jira,
231435
subject,
@@ -234,51 +438,120 @@ describe('commit message', function() {
234438
issues: longIssues
235439
})
236440
).to.equal(
237-
`${type}(${scope}): ${jiraUpperCase} ${subject}\n\n${longBodySplit}\n\n${breakingChange}${breaking}\n\n${longIssuesSplit}`
441+
`(${scope}): ${jiraUpperCase} ${subject}\n\n${longBodySplit}\n\n${breakingChange}${breaking}\n\n${longIssuesSplit}`
238442
);
239443
});
240-
it('header, long body, breaking change (with prefix entered), and long issues w/ scope', function() {
444+
it('header, long body, breaking change, and long issues w/ scope and w/ type', function() {
241445
expect(
242446
commitMessage({
243447
type,
244448
scope,
245449
jira,
246450
subject,
247451
body: longBody,
248-
breaking: `${breakingChange}${breaking}`,
452+
breaking,
249453
issues: longIssues
250454
})
251455
).to.equal(
252456
`${type}(${scope}): ${jiraUpperCase} ${subject}\n\n${longBodySplit}\n\n${breakingChange}${breaking}\n\n${longIssuesSplit}`
253457
);
254458
});
255-
it('header, body, breaking change, and issues w/ scope; exclamation mark enabled', function() {
459+
it('header, long body, breaking change (with prefix entered), and long issues w/ scope and w/ out type', function() {
460+
expect(
461+
commitMessage(
462+
{
463+
scope,
464+
jira,
465+
subject,
466+
body: longBody,
467+
breaking: `${breakingChange}${breaking}`,
468+
issues: longIssues
469+
},
470+
skipTypeOptions
471+
)
472+
).to.equal(
473+
`(${scope}): ${jiraUpperCase} ${subject}\n\n${longBodySplit}\n\n${breakingChange}${breaking}\n\n${longIssuesSplit}`
474+
);
475+
});
476+
it('header, long body, breaking change (with prefix entered), and long issues w/ scope and w/ type', function() {
256477
expect(
257478
commitMessage({
258479
type,
259480
scope,
260481
jira,
261482
subject,
262-
body,
263-
breaking,
264-
issues
265-
},
266-
{ ...defaultOptions, exclamationMark: true })
483+
body: longBody,
484+
breaking: `${breakingChange}${breaking}`,
485+
issues: longIssues
486+
})
487+
).to.equal(
488+
`${type}(${scope}): ${jiraUpperCase} ${subject}\n\n${longBodySplit}\n\n${breakingChange}${breaking}\n\n${longIssuesSplit}`
489+
);
490+
});
491+
it('header, body, breaking change, and issues w/ scope and w/o type; exclamation mark enabled', function() {
492+
expect(
493+
commitMessage(
494+
{
495+
scope,
496+
jira,
497+
subject,
498+
body,
499+
breaking,
500+
issues
501+
},
502+
{ ...skipTypeOptions, exclamationMark: true }
503+
)
504+
).to.equal(
505+
`(${scope})!: ${jiraUpperCase} ${subject}\n\n${body}\n\n${breakingChange}${breaking}\n\n${issues}`
506+
);
507+
});
508+
it('header, body, breaking change, and issues w/ scope and w/ type; exclamation mark enabled', function() {
509+
expect(
510+
commitMessage(
511+
{
512+
type,
513+
scope,
514+
jira,
515+
subject,
516+
body,
517+
breaking,
518+
issues
519+
},
520+
{ ...defaultOptions, exclamationMark: true }
521+
)
267522
).to.equal(
268523
`${type}(${scope})!: ${jiraUpperCase} ${subject}\n\n${body}\n\n${breakingChange}${breaking}\n\n${issues}`
269524
);
270525
});
271-
it('header, body, breaking change, and issues w/o scope; exclamation mark enabled', function() {
526+
it('header, body, breaking change, and issues w/o scope and w/o type; exclamation mark enabled', function() {
272527
expect(
273-
commitMessage({
274-
type,
275-
jira,
276-
subject,
277-
body,
278-
breaking,
279-
issues
280-
},
281-
{ ...defaultOptions, exclamationMark: true })
528+
commitMessage(
529+
{
530+
jira,
531+
subject,
532+
body,
533+
breaking,
534+
issues
535+
},
536+
{ ...skipTypeOptions, exclamationMark: true }
537+
)
538+
).to.equal(
539+
`!: ${jiraUpperCase} ${subject}\n\n${body}\n\n${breakingChange}${breaking}\n\n${issues}`
540+
);
541+
});
542+
it('header, body, breaking change, and issues w/o scope and w/ type; exclamation mark enabled', function() {
543+
expect(
544+
commitMessage(
545+
{
546+
type,
547+
jira,
548+
subject,
549+
body,
550+
breaking,
551+
issues
552+
},
553+
{ ...defaultOptions, exclamationMark: true }
554+
)
282555
).to.equal(
283556
`${type}!: ${jiraUpperCase} ${subject}\n\n${body}\n\n${breakingChange}${breaking}\n\n${issues}`
284557
);

‎index.js

+5
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ const options = {
2929
config.skipScope,
3030
defaults.skipScope
3131
),
32+
skipType: getEnvOrConfig(
33+
process.env.CZ_SKIP_SCOPE,
34+
config.skipScope,
35+
defaults.skipScope
36+
),
3237
skipDescription: getEnvOrConfig(
3338
process.env.CZ_SKIP_DESCRIPTION,
3439
config.skipDescription,

0 commit comments

Comments
 (0)
Please sign in to comment.