Skip to content

Commit 38ba08e

Browse files
author
Brett Uglow
committed
feat(build): add support for semantic-releasing and tests
1 parent ff5cd42 commit 38ba08e

File tree

7 files changed

+143
-26
lines changed

7 files changed

+143
-26
lines changed

.travis.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
sudo: false
2+
language: node_js
3+
node_js:
4+
- 5.11.0
5+
6+
# Need to specify a GCC compiler now!
7+
# https://docs.travis-ci.com/user/languages/javascript-with-nodejs#Node.js-v4-(or-io.js-v3)-compiler-requirements
8+
env:
9+
- CXX=g++-4.8
10+
11+
addons:
12+
apt:
13+
sources:
14+
- ubuntu-toolchain-r-test
15+
packages:
16+
- g++-4.8
17+
18+
before_install:
19+
- npm prune
20+
- npm set progress=false
21+
22+
install:
23+
- npm install --quiet
24+
- npm link
25+
26+
before_script:
27+
28+
script:
29+
- npm test
30+
31+
after_success:
32+
- npm run semantic-release
33+
34+
branches:
35+
except:
36+
- "/^v\\d+\\.\\d+\\.\\d+$/"
37+
38+
notifications:
39+
email:
40+
recipients:
41+
42+

README.md

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,34 @@
11
# cz-customizable-ghooks
2-
Integrate cz-customizable config with ghooks
2+
3+
Integrate cz-customizable config with ghooks to use a single configuration for commit message generation AND commit message hooks.
4+
5+
## Prerequisites
6+
7+
- git
8+
- Node >= 4.x
9+
- cz-customizable
10+
- ghooks
11+
12+
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`.
13+
14+
## Usage
15+
16+
```
17+
npm i cz-customizable ghooks cz-customizable-ghooks
18+
```
19+
20+
Then configure your package.json:
21+
22+
```
23+
// inside package.json
24+
...
25+
"config": {
26+
"cz-customizable": {
27+
"config": "path/to/your/cz-customizable-rules.js"
28+
},
29+
"ghooks": {
30+
"commit-msg": "./node_modules/cz-customizable-ghooks/index.js $2"
31+
}
32+
}
33+
...
34+
```

config/emptyConfig.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
'use strict';
2+
3+
module.exports = {
4+
5+
};
Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,24 @@ module.exports = {
1616
],
1717

1818
scopes: [
19-
{name: 'accounts'},
20-
{name: 'admin'},
21-
{name: 'exampleScope'},
22-
{name: 'changeMe'}
19+
{name: 'a'},
20+
{name: 'bb'},
21+
{name: 'ccc'},
22+
{name: 'dddd'}
2323
],
2424

2525
// it needs to match the value for field type. Eg.: 'fix'
26-
/*
27-
scopeOverrides: {
28-
fix: [
29-
30-
{name: 'merge'},
31-
{name: 'style'},
32-
{name: 'e2eTest'},
33-
{name: 'unitTest'}
34-
]
35-
},
36-
*/
26+
27+
scopeOverrides: {
28+
fix: [
29+
{name: 'merge'},
30+
{name: 'style'},
31+
{name: 'e2eTest'},
32+
{name: 'unitTest'}
33+
]
34+
},
35+
36+
3737

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

index.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,16 @@ try {
5050
process.exit(1);
5151
}
5252

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

5556
// Feature scopes are optional
56-
let FEAT_SCOPES = [];
57-
if (czConfig.scopes && czConfig.scopes.length !== 0) {
58-
FEAT_SCOPES = czConfig.scopes.map(item => item.name);
59-
}
57+
const FEAT_SCOPES = (czConfig.scopes || []).map(item => item.name);
6058

59+
// Fix-specific scopes are optional too
6160
let FIX_SCOPES = [];
62-
if (czConfig.scopeOverrides && czConfig.scopeOverrides.fix && czConfig.scopeOverrides.fix.length !== 0) {
63-
FIX_SCOPES = czConfig.scopes.map(item => item.name);
61+
if (czConfig.scopeOverrides && czConfig.scopeOverrides.fix && czConfig.scopeOverrides.fix.length) {
62+
FIX_SCOPES = czConfig.scopeOverrides.fix.map(item => item.name);
6463
}
6564

6665
function commitError() {

package.json

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "cz-customizable-ghooks",
3-
"version": "1.0.1",
4-
"description": "integrates ghook with cz-customizable",
3+
"version": "0.0.0-semantically-released",
4+
"description": "integrate ghooks with cz-customizable configuration",
55
"main": "index.js",
66
"repository": {
77
"type": "git",
@@ -17,13 +17,24 @@
1717
"url": "https://github.com/uglow/cz-customizable-ghooks/issues"
1818
},
1919
"homepage": "https://github.com/uglow/cz-customizable-ghooks#readme",
20+
"scripts": {
21+
"test": "node_modules/jasmine-node/bin/jasmine-node test/",
22+
"semantic-release": "semantic-release pre && npm publish && semantic-release post"
23+
},
2024
"config": {
2125
"cz-customizable": {
22-
"config": "config/commitMessageConfig.js"
26+
"config": "config/fullCommitMessageConfig.js"
2327
}
2428
},
2529
"dependencies": {
2630
"app-root-path": "1.0.0",
2731
"chalk": "1.1.3"
32+
},
33+
"engines": {
34+
"node": ">=4.x"
35+
},
36+
"devDependencies": {
37+
"jasmine-node": "1.14.5",
38+
"semantic-release-cli": "1.4.1"
2839
}
2940
}

test/ccg.spec.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
'use strict';
2+
3+
describe('cz-customizable-ghooks', () => {
4+
const rules = require('../index');
5+
6+
7+
it('should have a validationMessage function', () => {
8+
expect(typeof rules.validateMessage).toEqual('function');
9+
});
10+
11+
12+
describe('with complete config', () => {
13+
//const fullConfig = require('../config/commitMessageConfig');
14+
15+
const testData = [
16+
{msg: 'feat(a): valid type', expectedResult: true},
17+
{msg: 'fe(bb): incorrect type', expectedResult: false},
18+
{msg: 'fix(ccc): valid type', expectedResult: true}
19+
];
20+
21+
it('should accept commit messages which match the rules in the config', () => {
22+
testData.forEach(test => {
23+
expect(rules.validateMessage(test.msg)).toEqual(test.expectedResult);
24+
});
25+
});
26+
27+
});
28+
});

0 commit comments

Comments
 (0)