Skip to content

Commit

Permalink
feat: able to customize length limit of subject and warn when exceed (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
maple-leaf authored and leonardoanalista committed Aug 9, 2018
1 parent ec4f6d7 commit fdbf9ae
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
5 changes: 4 additions & 1 deletion cz-config-EXAMPLE.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ module.exports = {
},

allowCustomScopes: true,
allowBreakingChanges: ['feat', 'fix']
allowBreakingChanges: ['feat', 'fix'],

// limit subject length
subjectLimit: 100

};
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@ module.exports = {

prompter: function(cz, commit) {
var config = readConfigFile();
var subjectLimit = config.subjectLimit || 100;

log.info('\n\nLine 1 will be cropped at 100 characters. All other lines will be wrapped after 100 characters.\n');
log.info('\n\nLine 1 will be cropped at ' + subjectLimit + ' characters. All other lines will be wrapped after 100 characters.\n');

var questions = require('./questions').getQuestions(config, cz);

Expand Down
6 changes: 5 additions & 1 deletion questions.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,11 @@ module.exports = {
name: 'subject',
message: messages.subject,
validate: function(value) {
return !!value;
var limit = config.subjectLimit || 100;
if (value.length > limit) {
return 'Exceed limit: ' + limit;
}
return true;
},
filter: function(value) {
return value.charAt(0).toLowerCase() + value.slice(1);
Expand Down
14 changes: 12 additions & 2 deletions spec/questionsSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ describe('cz-customizable', function() {
fix: [{name: 'fixOverride'}]
},
allowCustomScopes: true,
allowBreakingChanges: ['feat']
allowBreakingChanges: ['feat'],
subjectLimit: 20
};

// question 1 - TYPE
Expand All @@ -51,7 +52,8 @@ describe('cz-customizable', function() {
expect(getQuestion(4).name).toEqual('subject');
expect(getQuestion(4).type).toEqual('input');
expect(getQuestion(4).message).toMatch(/IMPERATIVE tense description/);
expect(getQuestion(4).validate()).toEqual(false); //mandatory question
expect(getQuestion(4).validate('good subject')).toEqual(true);
expect(getQuestion(4).validate('bad subject that exceed limit')).toEqual('Exceed limit: 20');
expect(getQuestion(4).filter('Subject')).toEqual('subject');

// question 5 - BODY
Expand Down Expand Up @@ -84,6 +86,14 @@ describe('cz-customizable', function() {
expect(getQuestion(8).message(answers)).toMatch('Are you sure you want to proceed with the commit above?');
});

it('default length limit of subject should be 100', function() {
config = {
types: [{value: 'feat', name: 'feat: my feat'}]
};
expect(getQuestion(4).validate('good subject')).toEqual(true);
expect(getQuestion(4).validate('bad subject that exceed limit bad subject that exceed limitbad subject that exceed limit test test test')).toEqual('Exceed limit: 100');
});


describe('optional fixOverride and allowBreakingChanges', function() {

Expand Down

0 comments on commit fdbf9ae

Please sign in to comment.