Skip to content

Commit b49c969

Browse files
committed
build: add git commit message validation
1 parent 4acc8c8 commit b49c969

File tree

7 files changed

+645
-41
lines changed

7 files changed

+645
-41
lines changed

Diff for: .github/COMMIT_CONVENTION.md

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
## Git Commit Message Convention
2+
3+
> This is adapted from [Angular's commit convention](https://github.com/conventional-changelog/conventional-changelog/blob/master/packages/conventional-changelog-angular/convention.md).
4+
5+
#### Examples
6+
7+
Appears under "Features" header, pencil subheader:
8+
9+
```
10+
feat(pencil): add 'graphiteWidth' option
11+
```
12+
13+
Appears under "Bug Fixes" header, graphite subheader, with a link to issue #28:
14+
15+
```
16+
fix(graphite): stop graphite breaking when width < 0.1
17+
18+
close #28
19+
```
20+
21+
Appears under "Performance Improvements" header, and under "Breaking Changes" with the breaking change explanation:
22+
23+
```
24+
perf(pencil): remove graphiteWidth option
25+
26+
BREAKING CHANGE: The graphiteWidth option has been removed. The default graphite width of 10mm is always used for performance reason.
27+
```
28+
29+
The following commit and commit `667ecc1` do not appear in the changelog if they are under the same release. If not, the revert commit appears under the "Reverts" header.
30+
31+
```
32+
revert: feat(pencil): add 'graphiteWidth' option
33+
34+
This reverts commit 667ecc1654a317a13331b17617d973392f415f02.
35+
```
36+
37+
### Full Message Format
38+
39+
A commit message consists of a **header**, **body** and **footer**. The header has a **type**, **scope** and **subject**:
40+
41+
```
42+
<type>(<scope>): <subject>
43+
<BLANK LINE>
44+
<body>
45+
<BLANK LINE>
46+
<footer>
47+
```
48+
49+
The **header** is mandatory and the **scope** of the header is optional.
50+
51+
### Revert
52+
53+
If the commit reverts a previous commit, it should begin with `revert: `, followed by the header of the reverted commit. In the body it should say: `This reverts commit <hash>.`, where the hash is the SHA of the commit being reverted.
54+
55+
### Type
56+
57+
If the prefix is `feat`, `fix` or `perf`, it will appear in the changelog. However if there is any [BREAKING CHANGE](#footer), the commit will always appear in the changelog.
58+
59+
Other prefixes are up to your discretion. Suggested prefixes are `docs`, `chore`, `style`, `refactor`, and `test` for non-changelog related tasks.
60+
61+
### Scope
62+
63+
The scope could be anything specifying place of the commit change. For example `core`, `compiler`, `ssr`, `v-model`, `transition` etc...
64+
65+
### Subject
66+
67+
The subject contains succinct description of the change:
68+
69+
* use the imperative, present tense: "change" not "changed" nor "changes"
70+
* don't capitalize first letter
71+
* no dot (.) at the end
72+
73+
### Body
74+
75+
Just as in the **subject**, use the imperative, present tense: "change" not "changed" nor "changes".
76+
The body should include the motivation for the change and contrast this with previous behavior.
77+
78+
### Footer
79+
80+
The footer should contain any information about **Breaking Changes** and is also the place to
81+
reference GitHub issues that this commit **Closes**.
82+
83+
**Breaking Changes** should start with the word `BREAKING CHANGE:` with a space or two newlines. The rest of the commit message is then used for this.

Diff for: .github/CONTRIBUTING.md

+3-5
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,11 @@ After cloning the repo, run:
4343
$ npm install
4444
```
4545

46-
If you are on a Unix-like system, optionally install the Git pre-commit hook with:
46+
This would also run the `postinstall` script which will link git commit hooks if you are on a Unix-like system.
4747

48-
``` bash
49-
$ npm run install:hooks
50-
```
48+
### Commiting Changes
5149

52-
This will run ESLint on changed files before each commit.
50+
Commit messages should follow the [commit message convention](./COMMIT_CONVENTION.md) so that changelogs can be automatically generated. If git hooks have been properly linked, commit messages will be automatically validated upon commit. It is recommended to use `npm run commit` instead of `git commit`, which provides an interactive CLI for generating proper commit messages.
5351

5452
### Commonly used NPM scripts
5553

Diff for: .gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ dist/vue.common.min.js
99
test/e2e/reports
1010
test/e2e/screenshots
1111
coverage
12+
RELEASE_NOTE.md

Diff for: build/git-hooks/commit-msg

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env bash
2+
3+
# Validate commit log
4+
commit_regex='^Merge.+|(feat|fix|docs|style|refactor|perf|test|build|ci|chore|revert)(\(.+\))?: .{1,50}'
5+
6+
if ! grep -iqE "$commit_regex" "$1"; then
7+
echo
8+
echo " Error: proper commit message format is required for automated changelog generation."
9+
echo
10+
echo " - Use \`npm run commit\` to interactively generate a commit message."
11+
echo " - See .github/COMMIT_CONVENTION.md for more details."
12+
echo
13+
exit 1
14+
fi

Diff for: build/install-hooks.sh

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env bash
2+
3+
if test -e .git/hooks; then
4+
ln -sf ../../build/git-hooks/pre-commit .git/hooks/pre-commit && chmod +x .git/hooks/pre-commit
5+
ln -sf ../../build/git-hooks/commit-msg .git/hooks/commit-msg && chmod +x .git/hooks/commit-msg
6+
fi

Diff for: package.json

+10-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@
3737
"bench:ssr": "npm run build:ssr && node benchmarks/ssr/renderToString.js && node benchmarks/ssr/renderToStream.js",
3838
"release": "bash build/release.sh",
3939
"release:weex": "bash build/release-weex.sh",
40-
"install:hooks": "ln -fs ../../build/git-hooks/pre-commit .git/hooks/pre-commit"
40+
"postinstall": "bash build/install-hooks.sh",
41+
"commit": "git-cz"
4142
},
4243
"repository": {
4344
"type": "git",
@@ -67,7 +68,10 @@
6768
"chalk": "^1.1.3",
6869
"chromedriver": "^2.30.1",
6970
"codecov.io": "^0.1.6",
71+
"commitizen": "^2.9.6",
72+
"conventional-changelog-cli": "^1.3.1",
7073
"cross-spawn": "^5.1.0",
74+
"cz-conventional-changelog": "^2.0.0",
7175
"de-indent": "^1.0.2",
7276
"es6-promise": "^4.1.0",
7377
"eslint": "^3.0.0",
@@ -117,5 +121,10 @@
117121
"webpack": "^2.6.1",
118122
"weex-js-runtime": "^0.20.5",
119123
"weex-vdom-tester": "^0.2.0"
124+
},
125+
"config": {
126+
"commitizen": {
127+
"path": "./node_modules/cz-conventional-changelog"
128+
}
120129
}
121130
}

0 commit comments

Comments
 (0)