Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(engine): add support for disableSubjectLowerCase #127

Merged
merged 1 commit into from
Aug 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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