Skip to content

Commit df66875

Browse files
committedJul 31, 2020
feat(engine): add support for disableSubjectLowerCase
1 parent aae2548 commit df66875

File tree

4 files changed

+30
-6
lines changed

4 files changed

+30
-6
lines changed
 

‎README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ Like commitizen, you specify the configuration of cz-conventional-changelog thro
1919
"config": {
2020
"commitizen": {
2121
"path": "./node_modules/cz-conventional-changelog",
22+
"disableScopeLowerCase": false,
23+
"disableSubjectLowerCase": false,
2224
"maxHeaderWidth": 100,
2325
"maxLineWidth": 100,
2426
"defaultType": "",
@@ -39,6 +41,7 @@ Like commitizen, you specify the configuration of cz-conventional-changelog thro
3941
// ...
4042
}
4143
```
44+
4245
### Environment variables
4346

4447
The following environment varibles can be used to override any default configuration or package.json based configuration.
@@ -53,4 +56,3 @@ The following environment varibles can be used to override any default configura
5356
### Commitlint
5457

5558
If using the [commitlint](https://github.com/conventional-changelog/commitlint) js library, the "maxHeaderWidth" configuration property will default to the configuration of the "header-max-length" rule instead of the hard coded value of 100. This can be ovewritten by setting the 'maxHeaderWidth' configuration in package.json or the CZ_MAX_HEADER_WIDTH environment variable.
56-

‎engine.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ var maxSummaryLength = function(options, answers) {
2121
return options.maxHeaderWidth - headerLength(answers);
2222
};
2323

24-
var filterSubject = function(subject) {
24+
var filterSubject = function(subject, disableSubjectLowerCase) {
2525
subject = subject.trim();
26-
if (subject.charAt(0).toLowerCase() !== subject.charAt(0)) {
26+
if (!disableSubjectLowerCase && subject.charAt(0).toLowerCase() !== subject.charAt(0)) {
2727
subject =
2828
subject.charAt(0).toLowerCase() + subject.slice(1, subject.length);
2929
}
@@ -99,7 +99,7 @@ module.exports = function(options) {
9999
},
100100
default: options.defaultSubject,
101101
validate: function(subject, answers) {
102-
var filteredSubject = filterSubject(subject);
102+
var filteredSubject = filterSubject(subject, options.disableSubjectLowerCase);
103103
return filteredSubject.length == 0
104104
? 'subject is required'
105105
: filteredSubject.length <= maxSummaryLength(options, answers)
@@ -111,15 +111,15 @@ module.exports = function(options) {
111111
' characters.';
112112
},
113113
transformer: function(subject, answers) {
114-
var filteredSubject = filterSubject(subject);
114+
var filteredSubject = filterSubject(subject, options.disableSubjectLowerCase);
115115
var color =
116116
filteredSubject.length <= maxSummaryLength(options, answers)
117117
? chalk.green
118118
: chalk.red;
119119
return color('(' + filteredSubject.length + ') ' + subject);
120120
},
121121
filter: function(subject) {
122-
return filterSubject(subject);
122+
return filterSubject(subject, options.disableSubjectLowerCase);
123123
}
124124
},
125125
{

‎engine.test.js

+20
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,23 @@ describe('commit message', function() {
101101
)
102102
).to.equal(`${type}(${upperCaseScope}): ${subject}\n\n${body}`);
103103
});
104+
it('header and body w/ uppercase subject', function() {
105+
var upperCaseSubject = subject.toLocaleUpperCase();
106+
expect(
107+
commitMessage(
108+
{
109+
type,
110+
scope,
111+
subject: upperCaseSubject,
112+
body
113+
},
114+
{
115+
...defaultOptions,
116+
disableSubjectLowerCase: true
117+
}
118+
)
119+
).to.equal(`${type}(${scope}): ${upperCaseSubject}\n\n${body}`);
120+
});
104121
it('header, body and issues w/ out scope', function() {
105122
expect(
106123
commitMessage({
@@ -317,6 +334,9 @@ describe('defaults', function() {
317334
it('disableScopeLowerCase default', function() {
318335
expect(questionDefault('disableScopeLowerCase')).to.be.undefined;
319336
});
337+
it('disableSubjectLowerCase default', function() {
338+
expect(questionDefault('disableSubjectLowerCase')).to.be.undefined;
339+
});
320340
});
321341

322342
describe('prompts', function() {

‎index.js

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ var options = {
1414
defaultIssues: process.env.CZ_ISSUES || config.defaultIssues,
1515
disableScopeLowerCase:
1616
process.env.DISABLE_SCOPE_LOWERCASE || config.disableScopeLowerCase,
17+
disableSubjectLowerCase:
18+
process.env.DISABLE_SUBJECT_LOWERCASE || config.disableSubjectLowerCase,
1719
maxHeaderWidth:
1820
(process.env.CZ_MAX_HEADER_WIDTH &&
1921
parseInt(process.env.CZ_MAX_HEADER_WIDTH)) ||

0 commit comments

Comments
 (0)
Please sign in to comment.