Skip to content

Commit

Permalink
feat(engine): add support for disableSubjectLowerCase
Browse files Browse the repository at this point in the history
  • Loading branch information
zoffyzhang committed Jul 31, 2020
1 parent aae2548 commit df66875
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 6 deletions.
4 changes: 3 additions & 1 deletion README.md
Expand Up @@ -19,6 +19,8 @@ Like commitizen, you specify the configuration of cz-conventional-changelog thro
"config": {
"commitizen": {
"path": "./node_modules/cz-conventional-changelog",
"disableScopeLowerCase": false,
"disableSubjectLowerCase": false,
"maxHeaderWidth": 100,
"maxLineWidth": 100,
"defaultType": "",
Expand All @@ -39,6 +41,7 @@ Like commitizen, you specify the configuration of cz-conventional-changelog thro
// ...
}
```

### Environment variables

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

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.

10 changes: 5 additions & 5 deletions engine.js
Expand Up @@ -21,9 +21,9 @@ var maxSummaryLength = function(options, answers) {
return options.maxHeaderWidth - headerLength(answers);
};

var filterSubject = function(subject) {
var filterSubject = function(subject, disableSubjectLowerCase) {
subject = subject.trim();
if (subject.charAt(0).toLowerCase() !== subject.charAt(0)) {
if (!disableSubjectLowerCase && subject.charAt(0).toLowerCase() !== subject.charAt(0)) {
subject =
subject.charAt(0).toLowerCase() + subject.slice(1, subject.length);
}
Expand Down Expand Up @@ -99,7 +99,7 @@ module.exports = function(options) {
},
default: options.defaultSubject,
validate: function(subject, answers) {
var filteredSubject = filterSubject(subject);
var filteredSubject = filterSubject(subject, options.disableSubjectLowerCase);
return filteredSubject.length == 0
? 'subject is required'
: filteredSubject.length <= maxSummaryLength(options, answers)
Expand All @@ -111,15 +111,15 @@ module.exports = function(options) {
' characters.';
},
transformer: function(subject, answers) {
var filteredSubject = filterSubject(subject);
var filteredSubject = filterSubject(subject, options.disableSubjectLowerCase);
var color =
filteredSubject.length <= maxSummaryLength(options, answers)
? chalk.green
: chalk.red;
return color('(' + filteredSubject.length + ') ' + subject);
},
filter: function(subject) {
return filterSubject(subject);
return filterSubject(subject, options.disableSubjectLowerCase);
}
},
{
Expand Down
20 changes: 20 additions & 0 deletions engine.test.js
Expand Up @@ -101,6 +101,23 @@ describe('commit message', function() {
)
).to.equal(`${type}(${upperCaseScope}): ${subject}\n\n${body}`);
});
it('header and body w/ uppercase subject', function() {
var upperCaseSubject = subject.toLocaleUpperCase();
expect(
commitMessage(
{
type,
scope,
subject: upperCaseSubject,
body
},
{
...defaultOptions,
disableSubjectLowerCase: true
}
)
).to.equal(`${type}(${scope}): ${upperCaseSubject}\n\n${body}`);
});
it('header, body and issues w/ out scope', function() {
expect(
commitMessage({
Expand Down Expand Up @@ -317,6 +334,9 @@ describe('defaults', function() {
it('disableScopeLowerCase default', function() {
expect(questionDefault('disableScopeLowerCase')).to.be.undefined;
});
it('disableSubjectLowerCase default', function() {
expect(questionDefault('disableSubjectLowerCase')).to.be.undefined;
});
});

describe('prompts', function() {
Expand Down
2 changes: 2 additions & 0 deletions index.js
Expand Up @@ -14,6 +14,8 @@ var options = {
defaultIssues: process.env.CZ_ISSUES || config.defaultIssues,
disableScopeLowerCase:
process.env.DISABLE_SCOPE_LOWERCASE || config.disableScopeLowerCase,
disableSubjectLowerCase:
process.env.DISABLE_SUBJECT_LOWERCASE || config.disableSubjectLowerCase,
maxHeaderWidth:
(process.env.CZ_MAX_HEADER_WIDTH &&
parseInt(process.env.CZ_MAX_HEADER_WIDTH)) ||
Expand Down

0 comments on commit df66875

Please sign in to comment.