Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/beta'
Browse files Browse the repository at this point in the history
  • Loading branch information
pvdlg committed Jan 9, 2020
2 parents 7191b1d + 5ba9209 commit 99d15a9
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 37 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: ~> 1.0

import:
- semantic-release/semantic-release:.travis/node.yml
- semantic-release/semantic-release:.travis/node-versions.yml
- semantic-release/semantic-release:.travis/node-versions.yml@beta
- semantic-release/semantic-release:.travis/semantic-release.yml
- semantic-release/semantic-release:.travis/greenkeeper.yml
- semantic-release/semantic-release:.travis/codecov.yml
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

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

| Step | Description |
|------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------|
Expand Down Expand Up @@ -72,7 +73,7 @@ With this example:

#### releaseRules

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.
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).

##### Rules definition

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

##### Default rules matching
Expand Down Expand Up @@ -147,7 +148,7 @@ For example with `eslint` preset:
["@semantic-release/commit-analyzer", {
"preset": "eslint",
"releaseRules": [
{"tag": "Docs", "message":"/README/", "release": "patch"},
{"tag": "Docs", "message":"*README*", "release": "patch"},
{"tag": "New", "release": "patch"}
]
}],
Expand Down Expand Up @@ -181,7 +182,7 @@ With this configuration:
// File: config/release-rules.js
module.exports = [
{type: 'docs', scope: 'README', release: 'patch'},
{type: 'refactor', scope: /core-.*/, release: 'minor'},
{type: 'refactor', scope: 'core-*', release: 'minor'},
{type: 'refactor', release: 'patch'},
];
```
5 changes: 3 additions & 2 deletions lib/analyze-commit.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const {isMatchWith, isRegExp} = require('lodash');
const {isMatchWith, isString} = require('lodash');
const micromatch = require('micromatch');
const debug = require('debug')('semantic-release:commit-analyzer');
const RELEASE_TYPES = require('./default-release-types');
const compareReleaseTypes = require('./compare-release-types');
Expand All @@ -22,7 +23,7 @@ module.exports = (releaseRules, commit) => {
(!revert || commit.revert) &&
// Otherwise match the regular rules
isMatchWith(commit, rule, (obj, src) =>
/^\/.*\/$/.test(src) || isRegExp(src) ? new RegExp(/^\/(.*)\/$/.exec(src)[1]).test(obj) : undefined
isString(src) && isString(obj) ? micromatch.isMatch(obj, src) : undefined
)
)
.every(match => {
Expand Down
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
"conventional-commits-parser": "^3.0.7",
"debug": "^4.0.0",
"import-from": "^3.0.0",
"lodash": "^4.17.4"
"lodash": "^4.17.4",
"micromatch": "^3.1.10"
},
"devDependencies": {
"ava": "^2.0.0",
Expand All @@ -36,12 +37,12 @@
"conventional-changelog-express": "^2.0.0",
"conventional-changelog-jshint": "^2.0.0",
"nyc": "^15.0.0",
"semantic-release": "^15.0.0",
"semantic-release": "^16.0.0-beta",
"sinon": "^8.0.0",
"xo": "^0.25.0"
},
"engines": {
"node": ">=8.16"
"node": ">=10.13"
},
"files": [
"lib",
Expand Down Expand Up @@ -73,15 +74,14 @@
"all": true
},
"peerDependencies": {
"semantic-release": ">=15.8.0 <16.0.0"
"semantic-release": ">=16.0.0-beta <17.0.0"
},
"prettier": {
"printWidth": 120,
"trailingComma": "es5"
},
"publishConfig": {
"access": "public",
"tag": "next"
"access": "public"
},
"repository": {
"type": "git",
Expand Down
23 changes: 11 additions & 12 deletions test/analyze-commit.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ test('Match multiple criteria with revert', t => {
});

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

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

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

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

t.is(analyzeCommit(rules, match), 'minor');
t.is(analyzeCommit(rules, notMatch), undefined);
t.is(analyzeCommit([{type: 'feat'}], commit), undefined);
});

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

t.is(analyzeCommit(rules, match), 'minor');
t.is(analyzeCommit(rules, match2), 'minor');
t.is(analyzeCommit(rules, notMatch), undefined);
});

Expand Down
13 changes: 5 additions & 8 deletions test/integration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ test('Accept a "parseOpts" object as option', async t => {
{hash: '456', message: '%%FEATURE%% Second feature (fixes #456)'},
];
const releaseType = await analyzeCommits(
{parserOpts: {headerPattern: /^%%(.*?)%% (.*)$/, headerCorrespondence: ['tag', 'shortDesc']}},
{parserOpts: {headerPattern: /^%%(?<type>.*?)%% (?<subject>.*)$/, headerCorrespondence: ['tag', 'shortDesc']}},
{cwd, commits, logger: t.context.logger}
);

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

test('Allow to use regex in "releaseRules" configuration', async t => {
const commits = [
{hash: '123', message: 'Chore: First chore (fixes #123)'},
{hash: '456', message: 'Docs: update README (fixes #456)'},
];
test('Allow to use glob in "releaseRules" configuration', async t => {
const commits = [{message: 'Chore: First chore (fixes #123)'}, {message: 'Docs: update README (fixes #456)'}];
const releaseType = await analyzeCommits(
{
preset: 'eslint',
releaseRules: [
{tag: 'Chore', release: 'patch'},
{message: '/README/', release: 'minor'},
{message: '*README*', release: 'minor'},
],
},
{cwd, commits, logger: t.context.logger}
Expand Down
15 changes: 12 additions & 3 deletions test/load-parser-config.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,21 @@ test('Load "conventional-changelog-angular" by default', async t => {
});

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

t.is(customParserOpts.headerPattern, parserOpts.headerPattern);
t.deepEqual(customParserOpts.headerCorrespondence, parserOpts.headerCorrespondence);
});

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

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

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

0 comments on commit 99d15a9

Please sign in to comment.