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: Added possibility to use regex to remove text from the commit message #605

Closed
wants to merge 8 commits into from
Closed
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,5 @@ $RECYCLE.BIN/
# Windows shortcuts
*.lnk

# End of https://www.gitignore.io/api/macos,windows,linux,node
# End of https://www.gitignore.io/api/macos,windows,linux,node
/.vs
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,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). | - |
| `regexRemove` | Optional regular that will be used to clean up de message in the commit. For example to remove the Merged PR xxxx: part from a devops commit | - |

**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
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const debug = debugFactory("semantic-release:commit-analyzer");
* @param {String} pluginConfig.config Requireable 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 {Object} pluginConfig.parserOpts Additional `conventional-changelog-parser` options that will overwrite ones loaded by `preset` or `config`.
* @param {Object} pluginConfig.regexRemove Optional regular that will be used to clean up de message in the commit. For example to remove the Merged PR xxxx: part from a devops commit
* @param {Object} context The semantic-release context.
* @param {Array<Object>} context.commits The commits to analyze.
* @param {String} context.cwd The current working directory.
Expand All @@ -41,7 +42,7 @@ export async function analyzeCommits(pluginConfig, context) {

return true;
})
.map(({ message, ...commitProps }) => ({ rawMsg: message, message, ...commitProps, ...parser(message, config) }))
.map(({ message, ...commitProps }) => ({ rawMsg: message, message, ...commitProps, ...parser(pluginConfig.regexRemove ? message.replace(new RegExp(pluginConfig.regexRemove), "") : message, config) }))
).every(({ rawMsg, ...commit }) => {
logger.log(`Analyzing commit: %s`, rawMsg);
let commitReleaseType;
Expand Down
21 changes: 6 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
{
"name": "@semantic-release/commit-analyzer",
"name": "@tweeat/commit-analyzer",
"description": "semantic-release plugin to analyze commits with conventional-changelog",
"version": "0.0.0-development",
"version": "1.0.0",
"type": "module",
"author": "Pierre Vanduynslager (https://twitter.com/@pvdlg_)",
"author": "Gert-Jan Naaktgeboren",
"ava": {
"files": [
"test/**/*.test.js"
]
},
"bugs": {
"url": "https://github.com/semantic-release/commit-analyzer/issues"
"url": "https://github.com/Gert-Jan2AT/commit-analyzer"
},
"contributors": [
"Stephan Bönnemann <[email protected]> (http://boennemann.me)",
"Gregor Martynus (https://twitter.com/gr2m)"
],
"dependencies": {
"conventional-changelog-angular": "^7.0.0",
"conventional-commits-filter": "^4.0.0",
Expand Down Expand Up @@ -45,7 +41,7 @@
"lib",
"index.js"
],
"homepage": "https://github.com/semantic-release/commit-analyzer#readme",
"homepage": "https://github.com/Gert-Jan2AT/commit-analyzer#readme",
"keywords": [
"changelog",
"commit-analyzer",
Expand Down Expand Up @@ -83,7 +79,7 @@
},
"repository": {
"type": "git",
"url": "https://github.com/semantic-release/commit-analyzer.git"
"url": "git+https://github.com/Gert-Jan2AT/commit-analyzer.git"
},
"scripts": {
"lint": "prettier --check \"*.{js,json,md}\" \".github/**/*.{md,yml}\" \"{bin,lib,test}/*.js\"",
Expand All @@ -92,10 +88,5 @@
"semantic-release": "semantic-release",
"test": "c8 ava -v",
"test:ci": "c8 ava -v"
},
"renovate": {
"extends": [
"github>semantic-release/.github:renovate-config"
]
}
}