Skip to content

feat(engine): add ci skip directive for docs/chore #42

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

Closed
wants to merge 4 commits into from
Closed
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
51 changes: 45 additions & 6 deletions engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ var map = require('lodash.map');
var longest = require('longest');
var rightPad = require('right-pad');

var filter = function(array) {
return array.filter(function(x) {
return x;
});
};

// This can be any kind of SystemJS compatible module.
// We use Commonjs here, but ES6 or AMD would do just
// fine.
Expand Down Expand Up @@ -32,7 +38,8 @@ module.exports = function (options) {
//
// By default, we'll de-indent your commit
// template and will keep empty lines.
prompter: function(cz, commit) {
prompter: function (cz, commit) {

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

// Let's ask some questions of the user
Expand All @@ -48,6 +55,14 @@ module.exports = function (options) {
name: 'type',
message: 'Select the type of change that you\'re committing:',
choices: choices
}, {
type: 'confirm',
name: 'skipCI',
message: 'Should CI (tests or builds) be skipped for this commit?',
default: true,
when: function (answers) {
return answers.type === 'docs' || answers.type === 'chore'
}
}, {
type: 'input',
name: 'scope',
Expand All @@ -62,10 +77,14 @@ module.exports = function (options) {
message: 'Provide a longer description of the change:\n'
}, {
type: 'input',
name: 'footer',
message: 'List any breaking changes or issues closed by this change:\n'
name: 'breaking',
message: 'List any breaking changes:\n'
}, {
type: 'input',
name: 'issues',
message: 'List any issues closed by this change:\n'
}
]).then(function(answers) {
]).then(function (answers) {

var maxLineWidth = 100;

Expand All @@ -80,12 +99,32 @@ module.exports = function (options) {
var scope = answers.scope.trim();
scope = scope ? '(' + answers.scope.trim() + ')' : '';

var hasSkip = ['[ci skip]', '[skip ci]'].some(v => {
return (
answers.subject.indexOf(v) > -1 ||
answers.body.indexOf(v) > -1
)
});

var addSkip = !hasSkip && answers.skipCI

// Hard limit this line
var head = (answers.type + scope + ': ' + answers.subject.trim()).slice(0, maxLineWidth);
var head = (answers.type + scope + ': ' + answers.subject.trim())
.slice(0, addSkip ? maxLineWidth - 10 : maxLineWidth);

if (addSkip) head += ' [ci skip]';

// Wrap these lines at 100 characters
var body = wrap(answers.body, wrapOptions);
var footer = wrap(answers.footer, wrapOptions);

// Apply breaking change prefix, removing it if already present
var breaking = answers.breaking.trim();
breaking = breaking ? 'BREAKING CHANGE: ' + breaking.replace(/^BREAKING CHANGE: /, '') : '';
breaking = wrap(breaking, wrapOptions);

var issues = wrap(answers.issues, wrapOptions);

var footer = filter([ breaking, issues ]).join('\n\n');

commit(head + '\n\n' + body + '\n\n' + footer);
});
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"word-wrap": "^1.0.3"
},
"devDependencies": {
"commitizen": "2.9.5",
"commitizen": "2.9.6",
"semantic-release": "^6.3.2"
},
"czConfig": {
Expand Down