Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: make the use of default release rules optional #211

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ With this example:
| `parserOpts` | Additional [conventional-commits-parser](https://github.com/conventional-changelog/conventional-changelog/tree/master/packages/conventional-commits-parser#conventionalcommitsparseroptions) options that will extends the ones loaded by `preset` or `config`. 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. | - |
| `releaseRules` | An external module, a path to a module or an `Array` of rules. See [`releaseRules`](#releaserules). | See [`releaseRules`](#releaserules) |
| `presetConfig` | Additional configuration passed to the [conventional-changelog](https://github.com/conventional-changelog/conventional-changelog) preset. Used for example with [conventional-changelog-conventionalcommits](https://github.com/conventional-changelog/conventional-changelog-config-spec/blob/master/versions/2.0.0/README.md). | - |
| `useDefaultReleaseRules` | Boolean to control whether or not to use the default rules. See [default rules](lib/default-release-rules.js). | `false` |

**Notes**: in order to use a `preset` it must be installed (for example to use the [eslint preset](https://github.com/conventional-changelog/conventional-changelog/tree/master/packages/conventional-changelog-eslint) you must install it with `npm install conventional-changelog-eslint -D`)

Expand Down Expand Up @@ -182,3 +183,23 @@ module.exports = [
{type: 'refactor', release: 'patch'},
];
```
##### Ignoring default rules

If you want to sepcify your own custom commit style you can set the `useDefaultReleaseRules` property to `false`. And the [default rules](lib/default-release-rules.js) won't be used:
```json
{
"plugins": [
["@semantic-release/commit-analyzer", {
"useDefaultReleaseRules": false,
"releaseRules": [
{"tag": "Major", "release": "major"},
{"tag": "Minor", "release": "minor"},
{"tag": "Patch", "release": "patch"}
]
}],
"@semantic-release/release-notes-generator"
]
}
```

**Notes**: The value of the `preset` property will not have any effect when ignoring the default rules.
6 changes: 4 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const DEFAULT_RELEASE_RULES = require('./lib/default-release-rules');
* @param {String} pluginConfig.preset conventional-changelog preset ('angular', 'atom', 'codemirror', 'ember', 'eslint', 'express', 'jquery', 'jscs', 'jshint')
* @param {String} pluginConfig.config Requierable npm package with a custom conventional-changelog preset
* @param {String|Array} pluginConfig.releaseRules A `String` to load an external module or an `Array` of rules.
* @param {Boolean} pluginConfig.useDefaultReleaseRules A `Boolean` to control whether to use the default rules or not.
* @param {Object} pluginConfig.parserOpts Additional `conventional-changelog-parser` options that will overwrite ones loaded by `preset` or `config`.
* @param {Object} context The semantic-release context.
* @param {Array<Object>} context.commits The commits to analyze.
Expand All @@ -26,6 +27,7 @@ const DEFAULT_RELEASE_RULES = require('./lib/default-release-rules');
async function analyzeCommits(pluginConfig, context) {
const {commits, logger} = context;
const releaseRules = loadReleaseRules(pluginConfig, context);
const {useDefaultReleaseRules = true} = pluginConfig;
const config = await loadParserConfig(pluginConfig, context);
let releaseType = null;

Expand All @@ -50,8 +52,8 @@ async function analyzeCommits(pluginConfig, context) {
commitReleaseType = analyzeCommit(releaseRules, commit);
}

// If no custom releaseRules or none matched the commit, try with default releaseRules
if (isUndefined(commitReleaseType)) {
// If default releaseRules should be used, and no custom releaseRules, or none matched the commit: try with default releaseRules
if (useDefaultReleaseRules && isUndefined(commitReleaseType)) {
debug('Analyzing with default rules');
commitReleaseType = analyzeCommit(DEFAULT_RELEASE_RULES, commit);
}
Expand Down