Skip to content

Commit 99d15a9

Browse files
committed
Merge remote-tracking branch 'origin/beta'
2 parents 7191b1d + 5ba9209 commit 99d15a9

7 files changed

+44
-37
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ version: ~> 1.0
22

33
import:
44
- semantic-release/semantic-release:.travis/node.yml
5-
- semantic-release/semantic-release:.travis/node-versions.yml
5+
- semantic-release/semantic-release:.travis/node-versions.yml@beta
66
- semantic-release/semantic-release:.travis/semantic-release.yml
77
- semantic-release/semantic-release:.travis/greenkeeper.yml
88
- semantic-release/semantic-release:.travis/codecov.yml

README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
[![npm latest version](https://img.shields.io/npm/v/@semantic-release/commit-analyzer/latest.svg)](https://www.npmjs.com/package/@semantic-release/commit-analyzer)
1010
[![npm next version](https://img.shields.io/npm/v/@semantic-release/commit-analyzer/next.svg)](https://www.npmjs.com/package/@semantic-release/commit-analyzer)
11+
[![npm beta version](https://img.shields.io/npm/v/@semantic-release/commit-analyzer/beta.svg)](https://www.npmjs.com/package/@semantic-release/commit-analyzer)
1112

1213
| Step | Description |
1314
|------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------|
@@ -72,7 +73,7 @@ With this example:
7273

7374
#### releaseRules
7475

75-
Release 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. Those rules will be matched against the commit objects resulting of [conventional-commits-parser](https://github.com/conventional-changelog/conventional-changelog/tree/master/packages/conventional-commits-parser) parsing.
76+
Release 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. Those rules will be matched against the commit objects resulting of [conventional-commits-parser](https://github.com/conventional-changelog/conventional-changelog/tree/master/packages/conventional-commits-parser) parsing. Each rule property can be defined as a [glob](https://github.com/micromatch/micromatch#matching-features).
7677

7778
##### Rules definition
7879

@@ -84,7 +85,7 @@ This is an `Array` of rule objects. A rule object has a `release` property and 1
8485
"preset": "angular",
8586
"releaseRules": [
8687
{"type": "docs", "scope": "README", "release": "patch"},
87-
{"type": "refactor", "scope": "/core-.*/", "release": "minor"},
88+
{"type": "refactor", "scope": "core-*", "release": "minor"},
8889
{"type": "refactor", "release": "patch"},
8990
{"scope": "no-release", "release": false}
9091
]
@@ -103,7 +104,7 @@ See [release types](lib/default-release-types.js) for the release types hierarch
103104
With the previous example:
104105
- Commits with `type` 'docs' and `scope` 'README' will be associated with a `patch` release.
105106
- Commits with `type` 'refactor' and `scope` starting with 'core-' (i.e. 'core-ui', 'core-rules', ...) will be associated with a `minor` release.
106-
- Other commits with `type` 'refactor' (without `scope` or with a `scope` not matching the regexp `/core-.*/`) will be associated with a `patch` release.
107+
- Other commits with `type` 'refactor' (without `scope` or with a `scope` not matching the glob `core-*`) will be associated with a `patch` release.
107108
- Commits with scope `no-release` will not be associated with a release type.
108109

109110
##### Default rules matching
@@ -147,7 +148,7 @@ For example with `eslint` preset:
147148
["@semantic-release/commit-analyzer", {
148149
"preset": "eslint",
149150
"releaseRules": [
150-
{"tag": "Docs", "message":"/README/", "release": "patch"},
151+
{"tag": "Docs", "message":"*README*", "release": "patch"},
151152
{"tag": "New", "release": "patch"}
152153
]
153154
}],
@@ -181,7 +182,7 @@ With this configuration:
181182
// File: config/release-rules.js
182183
module.exports = [
183184
{type: 'docs', scope: 'README', release: 'patch'},
184-
{type: 'refactor', scope: /core-.*/, release: 'minor'},
185+
{type: 'refactor', scope: 'core-*', release: 'minor'},
185186
{type: 'refactor', release: 'patch'},
186187
];
187188
```

lib/analyze-commit.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
const {isMatchWith, isRegExp} = require('lodash');
1+
const {isMatchWith, isString} = require('lodash');
2+
const micromatch = require('micromatch');
23
const debug = require('debug')('semantic-release:commit-analyzer');
34
const RELEASE_TYPES = require('./default-release-types');
45
const compareReleaseTypes = require('./compare-release-types');
@@ -22,7 +23,7 @@ module.exports = (releaseRules, commit) => {
2223
(!revert || commit.revert) &&
2324
// Otherwise match the regular rules
2425
isMatchWith(commit, rule, (obj, src) =>
25-
/^\/.*\/$/.test(src) || isRegExp(src) ? new RegExp(/^\/(.*)\/$/.exec(src)[1]).test(obj) : undefined
26+
isString(src) && isString(obj) ? micromatch.isMatch(obj, src) : undefined
2627
)
2728
)
2829
.every(match => {

package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
"conventional-commits-parser": "^3.0.7",
2525
"debug": "^4.0.0",
2626
"import-from": "^3.0.0",
27-
"lodash": "^4.17.4"
27+
"lodash": "^4.17.4",
28+
"micromatch": "^3.1.10"
2829
},
2930
"devDependencies": {
3031
"ava": "^2.0.0",
@@ -36,12 +37,12 @@
3637
"conventional-changelog-express": "^2.0.0",
3738
"conventional-changelog-jshint": "^2.0.0",
3839
"nyc": "^15.0.0",
39-
"semantic-release": "^15.0.0",
40+
"semantic-release": "^16.0.0-beta",
4041
"sinon": "^8.0.0",
4142
"xo": "^0.25.0"
4243
},
4344
"engines": {
44-
"node": ">=8.16"
45+
"node": ">=10.13"
4546
},
4647
"files": [
4748
"lib",
@@ -73,15 +74,14 @@
7374
"all": true
7475
},
7576
"peerDependencies": {
76-
"semantic-release": ">=15.8.0 <16.0.0"
77+
"semantic-release": ">=16.0.0-beta <17.0.0"
7778
},
7879
"prettier": {
7980
"printWidth": 120,
8081
"trailingComma": "es5"
8182
},
8283
"publishConfig": {
83-
"access": "public",
84-
"tag": "next"
84+
"access": "public"
8585
},
8686
"repository": {
8787
"type": "git",

test/analyze-commit.test.js

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ test('Match multiple criteria with revert', t => {
3636
});
3737

3838
test('Match multiple criteria', t => {
39-
const commit = {type: 'feat', scope: 'test'};
39+
const commit = {type: 'feat', scope: 1};
4040

41-
t.is(analyzeCommit([{type: 'feat', scope: 'test', release: 'major'}], commit), 'major');
41+
t.is(analyzeCommit([{type: 'feat', scope: 1, release: 'major'}], commit), 'major');
4242
});
4343

4444
test('Match only if all criteria are verified', t => {
@@ -68,21 +68,20 @@ test('Return undefined if there is no match', t => {
6868
t.is(analyzeCommit([{type: 'feat', breaking: true, release: 'major'}], commit), undefined);
6969
});
7070

71-
test('Match with regex', t => {
72-
const rules = [{type: 'docs', scope: /test\(.*\)/, release: 'minor'}];
73-
const match = {type: 'docs', scope: 'test(readme): message'};
74-
const notMatch = {type: 'docs', scope: 'test2(readme): message'};
71+
test('Return undefined for commit with falsy properties', t => {
72+
const commit = {type: null};
7573

76-
t.is(analyzeCommit(rules, match), 'minor');
77-
t.is(analyzeCommit(rules, notMatch), undefined);
74+
t.is(analyzeCommit([{type: 'feat'}], commit), undefined);
7875
});
7976

80-
test('Match with regex as string', t => {
81-
const rules = [{type: 'docs', scope: '/test\\(.*\\)/', release: 'minor'}];
82-
const match = {type: 'docs', scope: 'test(readme): message'};
83-
const notMatch = {type: 'docs', scope: 'test2(readme): message'};
77+
test('Match with glob', t => {
78+
const rules = [{type: 'docs', scope: 'b*', release: 'minor'}];
79+
const match = {type: 'docs', scope: 'bar'};
80+
const match2 = {type: 'docs', scope: 'baz'};
81+
const notMatch = {type: 'docs', scope: 'foo'};
8482

8583
t.is(analyzeCommit(rules, match), 'minor');
84+
t.is(analyzeCommit(rules, match2), 'minor');
8685
t.is(analyzeCommit(rules, notMatch), undefined);
8786
});
8887

test/integration.test.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ test('Accept a "parseOpts" object as option', async t => {
6464
{hash: '456', message: '%%FEATURE%% Second feature (fixes #456)'},
6565
];
6666
const releaseType = await analyzeCommits(
67-
{parserOpts: {headerPattern: /^%%(.*?)%% (.*)$/, headerCorrespondence: ['tag', 'shortDesc']}},
67+
{parserOpts: {headerPattern: /^%%(?<type>.*?)%% (?<subject>.*)$/, headerCorrespondence: ['tag', 'shortDesc']}},
6868
{cwd, commits, logger: t.context.logger}
6969
);
7070

@@ -84,7 +84,7 @@ test('Accept a partial "parseOpts" object as option', async t => {
8484
const releaseType = await analyzeCommits(
8585
{
8686
config: 'conventional-changelog-eslint',
87-
parserOpts: {headerPattern: /^%%(.*?)%% (.*)$/, headerCorrespondence: ['type', 'shortDesc']},
87+
parserOpts: {headerPattern: /^%%(?<type>.*?)%% (?<subject>.*)$/, headerCorrespondence: ['type', 'shortDesc']},
8888
},
8989
{cwd, commits, logger: t.context.logger}
9090
);
@@ -174,17 +174,14 @@ test('Return "patch" if there is only types set to "patch", using default releas
174174
t.true(t.context.log.calledWith('Analysis of %s commits complete: %s release', 2, 'patch'));
175175
});
176176

177-
test('Allow to use regex in "releaseRules" configuration', async t => {
178-
const commits = [
179-
{hash: '123', message: 'Chore: First chore (fixes #123)'},
180-
{hash: '456', message: 'Docs: update README (fixes #456)'},
181-
];
177+
test('Allow to use glob in "releaseRules" configuration', async t => {
178+
const commits = [{message: 'Chore: First chore (fixes #123)'}, {message: 'Docs: update README (fixes #456)'}];
182179
const releaseType = await analyzeCommits(
183180
{
184181
preset: 'eslint',
185182
releaseRules: [
186183
{tag: 'Chore', release: 'patch'},
187-
{message: '/README/', release: 'minor'},
184+
{message: '*README*', release: 'minor'},
188185
],
189186
},
190187
{cwd, commits, logger: t.context.logger}

test/load-parser-config.test.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,21 @@ test('Load "conventional-changelog-angular" by default', async t => {
3838
});
3939

4040
test('Accept a "parserOpts" object as option', async t => {
41-
const customParserOpts = {headerPattern: /^##(.*?)## (.*)$/, headerCorrespondence: ['tag', 'shortDesc']};
41+
const customParserOpts = {
42+
headerPattern: /^##(?<type>.*?)## (?<subject>.*)$/,
43+
headerCorrespondence: ['tag', 'shortDesc'],
44+
};
4245
const parserOpts = await loadParserConfig({parserOpts: customParserOpts}, {cwd});
4346

4447
t.is(customParserOpts.headerPattern, parserOpts.headerPattern);
4548
t.deepEqual(customParserOpts.headerCorrespondence, parserOpts.headerCorrespondence);
4649
});
4750

4851
test('Accept a partial "parserOpts" object as option that overlaod a preset', async t => {
49-
const customParserOpts = {headerPattern: /^##(.*?)## (.*)$/, headerCorrespondence: ['tag', 'shortDesc']};
52+
const customParserOpts = {
53+
headerPattern: /^##(?<type>.*?)## (?<subject>.*)$/,
54+
headerCorrespondence: ['tag', 'shortDesc'],
55+
};
5056
const parserOpts = await loadParserConfig({parserOpts: customParserOpts, preset: 'angular'}, {cwd});
5157

5258
t.is(customParserOpts.headerPattern, parserOpts.headerPattern);
@@ -55,7 +61,10 @@ test('Accept a partial "parserOpts" object as option that overlaod a preset', as
5561
});
5662

5763
test('Accept a partial "parserOpts" object as option that overlaod a config', async t => {
58-
const customParserOpts = {headerPattern: /^##(.*?)## (.*)$/, headerCorrespondence: ['tag', 'shortDesc']};
64+
const customParserOpts = {
65+
headerPattern: /^##(?<type>.*?)## (?<subject>.*)$/,
66+
headerCorrespondence: ['tag', 'shortDesc'],
67+
};
5968
const parserOpts = await loadParserConfig(
6069
{parserOpts: customParserOpts, config: 'conventional-changelog-angular'},
6170
{cwd}

0 commit comments

Comments
 (0)