UNPKG

9.84 kBMarkdownView Raw
1# **commit-analyzer**
2
3Customizable commit-analyzer plugin for [semantic-release](https://github.com/semantic-release/semantic-release) based on [conventional-changelog](https://github.com/conventional-changelog/conventional-changelog)
4
5[![Travis](https://img.shields.io/travis/semantic-release/commit-analyzer.svg)](https://travis-ci.org/semantic-release/commit-analyzer)
6[![Codecov](https://img.shields.io/codecov/c/github/semantic-release/commit-analyzer.svg)](https://codecov.io/gh/semantic-release/commit-analyzer)
7[![Greenkeeper badge](https://badges.greenkeeper.io/semantic-release/commit-analyzer.svg)](https://greenkeeper.io/)
8
9## Options
10
11By default `commit-analyzer` uses the `angular` format described in [Angular convention](https://github.com/conventional-changelog/conventional-changelog/blob/master/packages/conventional-changelog-angular/convention.md) and the [default rules](lib/default/release-rules.js) for release.
12
13Additional options can be set within the plugin definition in `package.json` to use a different commit format and to customize it:
14
15```json
16{
17 "release": {
18 "analyzeCommits": {
19 "preset": "angular",
20 "releaseRules": [
21 {"type": "docs", "scope":"README", "release": "patch"},
22 {"type": "refactor", "release": "patch"},
23 {"type": "style", "release": "patch"}
24 ],
25 "parserOpts": {
26 "noteKeywords": ["BREAKING CHANGE", "BREAKING CHANGES", "BREAKING"]
27 }
28 }
29 }
30}
31```
32
33| Option | Description | Default |
34| -------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------- |
35| `preset` | [conventional-changelog](https://github.com/conventional-changelog/conventional-changelog) preset (possible values: `angular`, `atom`, `codemirror`, `ember`, `eslint`, `express`, `jquery`, `jscs`, `jshint`). | `angular` |
36| `config` | NPM package name of a custom [conventional-changelog](https://github.com/conventional-changelog/conventional-changelog) preset. | - |
37| `releaseRules` | An external module, a path to a module or an `Array` of rules. See [Release rules](#release-rules). | See [Release rules](#release-rules) |
38| `parserOpts` | Additional [conventional-commits-parser](https://github.com/conventional-changelog/conventional-changelog/tree/master/packages/conventional-commits-parser#conventionalcommitsparseroptions) options that will extends ones loaded by `preset` or `config`. See [Parser options](#parser-options). | - |
39
40**NOTE:** `config` will be overwritten by the values of `preset`. You should use either `preset` or `config`, but not both. Individual properties of `parserOpts` will overwrite ones loaded with `preset` or `config`.
41
42### Release Rules
43
44Release rules are used when deciding if the commits since the last release warrant a new release. If you define custom release rules the [default rules](lib/default/release-rules.js) will be used if nothing matched.
45
46#### Rules definition
47This is an `Array` of rule objects. A rule object has a `release` property and 1 or more criteria.
48```json
49{
50 "release": {
51 "analyzeCommits": {
52 "preset": "angular",
53 "releaseRules": [
54 {"type": "docs", "scope": "README", "release": "patch"},
55 {"type": "refactor", "scope": "/core-.*/", "release": "minor"},
56 {"type": "refactor", "release": "patch"}
57 ]
58 }
59 }
60}
61```
62#### Rules matching
63
64Each commit will be compared with each rule and when it matches, the commit will be associated with the release type in the rule's `release` property. If a commit match multiple rules, the highest release type (`major` > `minor` > `patch`) is associated with the commit.
65
66See [release types](lib/default/release-types.js) for the release types hierarchy.
67
68With the previous example:
69* Commits with `type` 'docs' and `scope` 'README' will be associated with a `patch` release.
70* Commits with `type` 'refactor' and `scope` starting with 'core-' (i.e. 'core-ui', 'core-rules', ...) will be associated with a `minor` release.
71* Other commits with `type` 'refactor' (without `scope` or with a `scope` not matching the regexp `/core-.*/`) will be associated with a `patch` release.
72
73#### Default rules matching
74
75If a commit doesn't match any rule in `releaseRules` it will be evaluated against the [default release rules](lib/default/release-rules.js).
76
77With the previous example:
78* Commits with a breaking change will be associated with a `minor` release.
79* Commits with `type` 'feat' will be associated with a `minor` release.
80* Commits with `type` 'fix' will be associated with a `patch` release.
81* Commits with `type` 'perf' will be associated with a `patch` release.
82
83#### No rules matching
84
85If a commit doesn't match any rules in `releaseRules` or in [default release rules](lib/default/release-rules.js) then no release type will be associated with the commit.
86
87With the previous example:
88* Commits with `type` 'style' will not be associated with a release type.
89* Commits with `type` 'test' will not be associated with a release type.
90* Commits with `type` 'chore' will not be associated with a release type.
91
92#### Multiple commits
93
94If there is multiple commits that match one or more rules, the one with the highest release type will determine the global release type.
95
96Considering the following commits:
97* `docs(README): Add more details to the API docs`
98* `feat(API): Add a new method to the public API`
99
100With the previous example the release type determine by the plugin will be `minor`.
101
102#### Specific commit properties
103
104The properties to set in the rules will depends on the commit style chosen. For example [conventional-changelog-angular](https://github.com/conventional-changelog/conventional-changelog/blob/master/packages/conventional-changelog-angular/index.js#L9-L13) use the commit properties `type`, `scope` and `subject` but [conventional-changelog-eslint](https://github.com/conventional-changelog/conventional-changelog/blob/master/packages/conventional-changelog-eslint/index.js#L9-L12) uses `tag` and `message`.
105
106For example with `eslint` preset:
107```json
108{
109 "release": {
110 "analyzeCommits": {
111 "preset": "eslint",
112 "releaseRules": [
113 {"tag": "Docs", "message":"/README/", "release": "patch"},
114 {"type": "New", "release": "patch"}
115 ]
116 }
117 }
118}
119```
120With this configuration:
121* Commits with `tag` 'Docs', that contains 'README' in their header message will be associated with a `patch` release.
122* Commits with `tag` 'New' will be associated with a `patch` release.
123* Commits with `tag` 'Breaking' will be associated with a `major` release (per [default release rules](lib/default/release-rules.js)).
124* Commits with `tag` 'Fix' will be associated with a `patch` release (per [default release rules](lib/default/release-rules.js)).
125* Commits with `tag` 'Update' will be associated with a `minor` release (per [default release rules](lib/default/release-rules.js)).
126* Commits with `tag` 'New' will be associated with a `minor` release (per [default release rules](lib/default/release-rules.js)).
127* All other commits will not be associated with a release type.
128
129#### External package / file
130
131`releaseRules` can also reference a module, either by it's `npm` name or path:
132```json
133{
134 "release": {
135 "analyzeCommits": {
136 "preset": "angular",
137 "releaseRules": "./config/release-rules.js"
138 }
139 }
140}
141```
142```js
143// File: config/release-rules.js
144module.exports = [
145 {type: 'docs', scope: 'README', release: 'patch'},
146 {type: 'refactor', scope: /core-.*/, release: 'minor'},
147 {type: 'refactor', release: 'patch'},
148];
149```
150
151### Parser Options
152
153Allow to overwrite specific [conventional-commits-parser](https://github.com/conventional-changelog/conventional-changelog/tree/master/packages/conventional-commits-parser#conventionalcommitsparseroptions) options. This is convenient to use a [conventional-changelog](https://github.com/conventional-changelog/conventional-changelog) preset with some customizations without having to create a new module.
154
155The following example uses [Angular convention](https://github.com/conventional-changelog/conventional-changelog/blob/master/packages/conventional-changelog-angular/convention.md) but will consider a commit to be a breaking change if it's body contains `BREAKING CHANGE`, `BREAKING CHANGES` or `BREAKING`. By default the [preset](https://github.com/conventional-changelog/conventional-changelog/blob/master/packages/conventional-changelog-angular/index.js#L14) checks only for `BREAKING CHANGE` and `BREAKING CHANGES`.
156```json
157{
158 "release": {
159 "analyzeCommits": {
160 "preset": "angular",
161 "parserOpts": {
162 "noteKeywords": ["BREAKING CHANGE", "BREAKING CHANGES", "BREAKING"],
163 }
164 }
165 }
166}
167```