Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cz-customizable

Package Overview
Dependencies
Maintainers
1
Versions
52
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cz-customizable - npm Package Compare versions

Comparing version 5.4.0 to 5.5.0

12

buildCommit.js

@@ -28,2 +28,12 @@ 'use strict';

function addTicketNumber(ticketNumber, config) {
if (!ticketNumber) {
return '';
}
if (config.ticketNumberPrefix) {
return config.ticketNumberPrefix + ticketNumber.trim() + ' ';
}
return ticketNumber.trim() + ' ';
}
function escapeSpecialChars(result) {

@@ -42,3 +52,3 @@ var specialChars = ['\`'];

// Hard limit this line
var head = (answers.type + addScope(answers.scope) + addSubject(answers.subject)).slice(0, maxLineWidth);
var head = (answers.type + addScope(answers.scope) + addTicketNumber(answers.ticketNumber, config) + addSubject(answers.subject)).slice(0, maxLineWidth);

@@ -45,0 +55,0 @@ // Wrap these lines at 100 characters

@@ -25,2 +25,7 @@ 'use strict';

allowTicketNumber: true,
isTicketNumberRequired: true,
ticketNumberPrefix: 'TICKET-',
ticketNumberRegExp: '\\d{1,5}',
// it needs to match the value for field type. Eg.: 'fix'

@@ -59,2 +64,3 @@ /*

};

2

package.json
{
"version": "5.4.0",
"version": "5.5.0",
"name": "cz-customizable",

@@ -4,0 +4,0 @@ "description": "Commitizen customizable adapter following the conventional-changelog format.",

'use strict';
var fs = require('fs');
var path = require('path');
var buildCommit = require('./buildCommit');

@@ -12,2 +14,19 @@ var log = require('winston');

var cwd = fs.realpathSync(process.cwd());
var packageData = require(path.join(cwd, 'package.json'));
function isValidateTicketNo(value, config) {
if (!value) {
return config.isTicketNumberRequired ? false : true;
}
if (!config.ticketNumberRegExp) {
return true;
}
var reg = new RegExp(config.ticketNumberRegExp);
if (value.replace(reg, '') !== '') {
return false;
}
return true;
}
module.exports = {

@@ -25,2 +44,9 @@

messages.customScope = messages.customScope || 'Denote the SCOPE of this change:';
if (!messages.ticketNumber) {
if (config.ticketNumberRegExp) {
messages.ticketNumber = messages.ticketNumberPattern || 'Enter the ticket number following this pattern (' + config.ticketNumberRegExp + ')\n';
} else {
messages.ticketNumber = 'Enter the ticket number:\n';
}
}
messages.subject = messages.subject || 'Write a SHORT, IMPERATIVE tense description of the change:\n';

@@ -84,2 +110,13 @@ messages.body = messages.body || 'Provide a LONGER description of the change (optional). Use "|" to break new line:\n';

type: 'input',
name: 'ticketNumber',
message: messages.ticketNumber,
when: function() {
return !!config.allowTicketNumber; // no ticket numbers allowed unless specifed
},
validate: function (value) {
return isValidateTicketNo(value, config);
}
},
{
type: 'input',
name: 'subject',

@@ -86,0 +123,0 @@ message: messages.subject,

@@ -267,2 +267,52 @@ 'use strict';

it('should call commit() function with ticket number', function() {
var answers = {
confirmCommit: 'yes',
type: 'feat',
scope: 'myScope',
subject: 'create a new cool feature',
ticketNumber: 'TICKET-1234'
};
var mockCz = getMockedCz(answers);
module.prompter(mockCz, commit);
expect(commit).toHaveBeenCalledWith('feat(myScope): TICKET-1234 create a new cool feature');
});
it('should call commit() function with ticket number and prefix', function() {
module.__set__({
// it mocks winston logging tool
log: {
info: function() {}
},
readConfigFile: function() {
return {
types: [{value: 'feat', name: 'feat: my feat'}],
scopes: [{name: 'myScope'}],
scopeOverrides: {
fix: [{name: 'fixOverride'}]
},
allowCustomScopes: true,
allowBreakingChanges: ['feat'],
breakingPrefix: 'WARNING:',
ticketNumberPrefix: 'TICKET-'
};
}
});
var answers = {
confirmCommit: 'yes',
type: 'feat',
scope: 'myScope',
subject: 'create a new cool feature',
ticketNumber: '1234'
};
var mockCz = getMockedCz(answers);
module.prompter(mockCz, commit);
expect(commit).toHaveBeenCalledWith('feat(myScope): TICKET-1234 create a new cool feature');
});
});

@@ -29,2 +29,6 @@ 'use strict';

allowBreakingChanges: ['feat'],
allowTicketNumber: true,
isTicketNumberRequired: true,
ticketNumberPrefix: 'TICKET-',
ticketNumberRegExp: '\\d{1,5}',
subjectLimit: 20

@@ -52,31 +56,37 @@ };

// question 4 - SUBJECT
expect(getQuestion(4).name).toEqual('subject');
// question 4 - TICKET_NUMBER
expect(getQuestion(4).name).toEqual('ticketNumber');
expect(getQuestion(4).type).toEqual('input');
expect(getQuestion(4).message).toMatch(/IMPERATIVE tense description/);
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');
expect(getQuestion(4).message.indexOf('Enter the ticket number following this pattern')).toEqual(0);
expect(getQuestion(4).validate()).toEqual(false); //mandatory question
// question 5 - BODY
expect(getQuestion(5).name).toEqual('body');
// question 5 - SUBJECT
expect(getQuestion(5).name).toEqual('subject');
expect(getQuestion(5).type).toEqual('input');
// question 6 - BREAKING CHANGE
expect(getQuestion(6).name).toEqual('breaking');
expect(getQuestion(5).message).toMatch(/IMPERATIVE tense description/);
expect(getQuestion(5).filter('Subject')).toEqual('subject');
expect(getQuestion(5).validate('bad subject that exceed limit')).toEqual('Exceed limit: 20');
expect(getQuestion(5).validate('good subject')).toEqual(true);
// question 6 - BODY
expect(getQuestion(6).name).toEqual('body');
expect(getQuestion(6).type).toEqual('input');
expect(getQuestion(6).when({type: 'feat'})).toEqual(true);
expect(getQuestion(6).when({type: 'fix'})).toEqual(false);
// question 7 - FOOTER
expect(getQuestion(7).name).toEqual('footer');
// question 7 - BREAKING CHANGE
expect(getQuestion(7).name).toEqual('breaking');
expect(getQuestion(7).type).toEqual('input');
expect(getQuestion(7).when({type: 'fix'})).toEqual(true);
expect(getQuestion(7).when({type: 'WIP'})).toEqual(false);
expect(getQuestion(7).when({type: 'feat'})).toEqual(true);
expect(getQuestion(7).when({type: 'fix'})).toEqual(false);
//question 8, last one, CONFIRM COMMIT OR NOT
expect(getQuestion(8).name).toEqual('confirmCommit');
expect(getQuestion(8).type).toEqual('expand');
// question 8 - FOOTER
expect(getQuestion(8).name).toEqual('footer');
expect(getQuestion(8).type).toEqual('input');
expect(getQuestion(8).when({type: 'fix'})).toEqual(true);
expect(getQuestion(8).when({type: 'WIP'})).toEqual(false);
//question 9, last one, CONFIRM COMMIT OR NOT
expect(getQuestion(9).name).toEqual('confirmCommit');
expect(getQuestion(9).type).toEqual('expand');
var answers = {

@@ -88,3 +98,3 @@ confirmCommit: 'yes',

};
expect(getQuestion(8).message(answers)).toMatch('Are you sure you want to proceed with the commit above?');
expect(getQuestion(9).message(answers)).toMatch('Are you sure you want to proceed with the commit above?');
});

@@ -96,4 +106,4 @@

};
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');
expect(getQuestion(5).validate('good subject')).toEqual(true);
expect(getQuestion(5).validate('bad subject that exceed limit bad subject that exceed limitbad subject that exceed limit test test test')).toEqual('Exceed limit: 100');
});

@@ -110,3 +120,3 @@

};
expect(getQuestion(6).name).toEqual('breaking');
expect(getQuestion(7).name).toEqual('breaking');

@@ -117,3 +127,3 @@ var answers = {

expect(getQuestion(6).when(answers)).toEqual(false); // not allowed
expect(getQuestion(7).when(answers)).toEqual(false); // not allowed
});

@@ -127,3 +137,3 @@

};
expect(getQuestion(6).name).toEqual('breaking');
expect(getQuestion(7).name).toEqual('breaking');

@@ -134,3 +144,3 @@ var answers = {

expect(getQuestion(6).when(answers)).toEqual(true); // allowed
expect(getQuestion(7).when(answers)).toEqual(true); // allowed
});

@@ -164,3 +174,82 @@

describe('no TicketNumber question', function() {
it('should use scope override', function() {
config = {
types: [{value: 'feat', name: 'feat: my feat'}],
allowTicketNumber: false
};
// question 4 with
expect(getQuestion(4).name).toEqual('ticketNumber');
expect(getQuestion(4).when()).toEqual(false);
});
});
describe('TicketNumber', function() {
it('disable TicketNumber question', function() {
config = {
types: [{value: 'feat', name: 'feat: my feat'}],
allowTicketNumber: false
};
// question 4 with
expect(getQuestion(4).name).toEqual('ticketNumber');
expect(getQuestion(4).when()).toEqual(false);
});
it('custom message defined', function() {
config = {
types: [{value: 'feat', name: 'feat: my feat'}],
allowTicketNumber: true,
messages: {
ticketNumber: 'ticket number'
}
};
// question 4 with
expect(getQuestion(4).name).toEqual('ticketNumber');
expect(getQuestion(4).message).toEqual('ticket number');
});
describe('validation', function() {
it('invalid because empty and required', function() {
config = {
isTicketNumberRequired: true
};
expect(getQuestion(4).validate('')).toEqual(false);
});
it('empty but valid because optional', function() {
config = {
isTicketNumberRequired: false
};
expect(getQuestion(4).validate('')).toEqual(true);
});
it('valid because there is no regexp defined', function() {
config = {
isTicketNumberRequired: true,
ticketNumberRegExp: undefined
};
expect(getQuestion(4).validate('21234')).toEqual(true);
});
it('invalid because regexp don\'t match', function() {
config = {
isTicketNumberRequired: true,
ticketNumberRegExp: '\\d{1,5}'
};
expect(getQuestion(4).validate('sddsa')).toEqual(false);
});
it('valid because regexp match', function() {
config = {
isTicketNumberRequired: true,
ticketNumberRegExp: '\\d{1,5}'
};
expect(getQuestion(4).validate('12345')).toEqual(true);
});
});
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc