Skip to content

Commit

Permalink
feat(engine): allow user to add [skip-ci] in head of commit message
Browse files Browse the repository at this point in the history
re #5
  • Loading branch information
ashwinaggarwal committed Mar 27, 2019
1 parent 5419a8a commit 049bc9a
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 4 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ cache:
notifications:
email: false
node_js:
- '4'
- '8.9.4'
before_install:
- npm i -g npm@^2.0.0
- npm i -g npm@^5.6.0
before_script:
- npm prune
after_success:
Expand Down
17 changes: 17 additions & 0 deletions __tests__/__snapshots__/engine.spec.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Engine should add [skip-ci] to commit message head if user said yes to skip deployment 1`] = `
"chore(buildspec): [skip-ci] This is a test message
fix #Issue01"
`;

exports[`Engine should not add [skip-ci] to commit message head if user said no (default) to skip deployment 1`] = `
"chore(buildspec): This is a test message
fix #Issue01"
`;
42 changes: 42 additions & 0 deletions __tests__/engine.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
describe('Engine', () => {
let engine = require('../index');
let answersMock = {
type: 'chore',
scope: 'buildspec',
subject: 'This is a test message',
body: '',
isBreaking: false,
needDeployment: true,
isIssueAffected: true,
issues: 'fix #Issue01'
};

let cz = {
prompt: jest.fn()
};

beforeEach(() => {
cz.prompt.mockReset();
});

test('should not add [skip-ci] to commit message head if user said no (default) to skip deployment', (done) => {
cz.prompt.mockReturnValue(Promise.resolve(answersMock));
engine.prompter(cz, (commitMessage) => {
expect(commitMessage).toMatchSnapshot();
expect(/\[skip-ci\]/g.test(commitMessage)).toBeFalsy();
done();
});
});

test('should add [skip-ci] to commit message head if user said yes to skip deployment', (done) => {
cz.prompt.mockReturnValue(Promise.resolve({
...answersMock,
needDeployment: false
}));
engine.prompter(cz, (commitMessage) => {
expect(commitMessage).toMatchSnapshot();
expect(/\[skip-ci\]/g.test(commitMessage)).toBeTruthy();
done();
});
});
});
10 changes: 9 additions & 1 deletion engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ module.exports = function (options) {
when: function(answers) {
return answers.isBreaking;
}
}, {
type: 'confirm',
name: 'needDeployment',
message: 'Does this commit needs to be deployed?',
default: true
}, {
type: 'confirm',
name: 'isIssueAffected',
Expand Down Expand Up @@ -123,8 +128,11 @@ module.exports = function (options) {
scope = scope.trim();
scope = scope ? '(' + scope + ')' : '';

// add [skip-ci] in commit message to trip deployment pipeline when necessary
var skipDeploymentMsg = answers.needDeployment ? '' : '[skip-ci] ';

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

// Wrap these lines at 100 characters
var body = wrap(answers.body, wrapOptions);
Expand Down
9 changes: 8 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"main": "index.js",
"scripts": {
"commit": "git-cz",
"test": "echo 'Tests need to be setup!'",
"test": "jest",
"test:debug": "node --inspect-brk node_modules/.bin/jest --runInBand --no-cache",
"semantic-release": "semantic-release pre && npm publish && semantic-release post"
},
"homepage": "https://github.com/commitizen/cz-conventional-changelog",
Expand All @@ -24,8 +25,14 @@
},
"devDependencies": {
"commitizen": "2.9.6",
"jest": "^24.5.0",
"semantic-release": "^6.3.2"
},
"jest": {
"testMatch": [
"**/__tests__/**/*.spec.js"
]
},
"config": {
"commitizen": {
"path": "./index.js"
Expand Down

0 comments on commit 049bc9a

Please sign in to comment.