Skip to content

Commit

Permalink
feat(build): add support for semantic-releasing and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Brett Uglow committed May 12, 2016
1 parent ff5cd42 commit 38ba08e
Show file tree
Hide file tree
Showing 7 changed files with 143 additions and 26 deletions.
42 changes: 42 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
sudo: false
language: node_js
node_js:
- 5.11.0

# Need to specify a GCC compiler now!
# https://docs.travis-ci.com/user/languages/javascript-with-nodejs#Node.js-v4-(or-io.js-v3)-compiler-requirements
env:
- CXX=g++-4.8

addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- g++-4.8

before_install:
- npm prune
- npm set progress=false

install:
- npm install --quiet
- npm link

before_script:

script:
- npm test

after_success:
- npm run semantic-release

branches:
except:
- "/^v\\d+\\.\\d+\\.\\d+$/"

notifications:
email:
recipients:
- [email protected]

34 changes: 33 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,34 @@
# cz-customizable-ghooks
Integrate cz-customizable config with ghooks

Integrate cz-customizable config with ghooks to use a single configuration for commit message generation AND commit message hooks.

## Prerequisites

- git
- Node >= 4.x
- cz-customizable
- ghooks

Make sure you have a git repository (`git init`) BEFORE installing ghooks, otherwise you have to take extra steps if you install ghooks before running `git init`.

## Usage

```
npm i cz-customizable ghooks cz-customizable-ghooks
```

Then configure your package.json:

```
// inside package.json
...
"config": {

This comment has been minimized.

Copy link
@leonardoanalista

leonardoanalista May 17, 2016

Collaborator

fyi: I have made the cz-customizible configuration option 2 deprecated: leoforfree/cz-customizable@6cea17f.
This aligns with the next major version of Commitizen.
It means there will be only one way to configure cz-customizible in the future.

"cz-customizable": {
"config": "path/to/your/cz-customizable-rules.js"
},
"ghooks": {
"commit-msg": "./node_modules/cz-customizable-ghooks/index.js $2"
}
}
...
```
5 changes: 5 additions & 0 deletions config/emptyConfig.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use strict';

module.exports = {

};
30 changes: 15 additions & 15 deletions config/commitMessageConfig.js → config/fullCommitMessageConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,24 @@ module.exports = {
],

scopes: [
{name: 'accounts'},
{name: 'admin'},
{name: 'exampleScope'},
{name: 'changeMe'}
{name: 'a'},
{name: 'bb'},
{name: 'ccc'},
{name: 'dddd'}
],

// it needs to match the value for field type. Eg.: 'fix'
/*
scopeOverrides: {
fix: [
{name: 'merge'},
{name: 'style'},
{name: 'e2eTest'},
{name: 'unitTest'}
]
},
*/

scopeOverrides: {
fix: [
{name: 'merge'},
{name: 'style'},
{name: 'e2eTest'},
{name: 'unitTest'}
]
},



allowCustomScopes: true,
allowBreakingChanges: ['feat', 'fix']
Expand Down
13 changes: 6 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,16 @@ try {
process.exit(1);
}

const TYPES = czConfig.types.map(item => item.value);
// These are mandatory in czConfig, but guard anyway
const TYPES = (czConfig.types || []).map(item => item.value);

// Feature scopes are optional
let FEAT_SCOPES = [];
if (czConfig.scopes && czConfig.scopes.length !== 0) {
FEAT_SCOPES = czConfig.scopes.map(item => item.name);
}
const FEAT_SCOPES = (czConfig.scopes || []).map(item => item.name);

// Fix-specific scopes are optional too
let FIX_SCOPES = [];
if (czConfig.scopeOverrides && czConfig.scopeOverrides.fix && czConfig.scopeOverrides.fix.length !== 0) {
FIX_SCOPES = czConfig.scopes.map(item => item.name);
if (czConfig.scopeOverrides && czConfig.scopeOverrides.fix && czConfig.scopeOverrides.fix.length) {
FIX_SCOPES = czConfig.scopeOverrides.fix.map(item => item.name);
}

function commitError() {
Expand Down
17 changes: 14 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "cz-customizable-ghooks",
"version": "1.0.1",
"description": "integrates ghook with cz-customizable",
"version": "0.0.0-semantically-released",
"description": "integrate ghooks with cz-customizable configuration",
"main": "index.js",
"repository": {
"type": "git",
Expand All @@ -17,13 +17,24 @@
"url": "https://github.com/uglow/cz-customizable-ghooks/issues"
},
"homepage": "https://github.com/uglow/cz-customizable-ghooks#readme",
"scripts": {
"test": "node_modules/jasmine-node/bin/jasmine-node test/",
"semantic-release": "semantic-release pre && npm publish && semantic-release post"
},
"config": {
"cz-customizable": {
"config": "config/commitMessageConfig.js"
"config": "config/fullCommitMessageConfig.js"
}
},
"dependencies": {
"app-root-path": "1.0.0",
"chalk": "1.1.3"
},
"engines": {
"node": ">=4.x"
},
"devDependencies": {
"jasmine-node": "1.14.5",
"semantic-release-cli": "1.4.1"
}
}
28 changes: 28 additions & 0 deletions test/ccg.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
'use strict';

describe('cz-customizable-ghooks', () => {
const rules = require('../index');


it('should have a validationMessage function', () => {
expect(typeof rules.validateMessage).toEqual('function');
});


describe('with complete config', () => {
//const fullConfig = require('../config/commitMessageConfig');

const testData = [
{msg: 'feat(a): valid type', expectedResult: true},
{msg: 'fe(bb): incorrect type', expectedResult: false},
{msg: 'fix(ccc): valid type', expectedResult: true}
];

it('should accept commit messages which match the rules in the config', () => {
testData.forEach(test => {
expect(rules.validateMessage(test.msg)).toEqual(test.expectedResult);
});
});

});
});

0 comments on commit 38ba08e

Please sign in to comment.