@myparcel-dev/semantic-release-release-notes-generator 10.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2017 Pierre-Denis Vanduynslager
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,70 @@
1
+ # **release-notes-generator**
2
+
3
+ [**semantic-release**](https://github.com/semantic-release/semantic-release) plugin to generate changelog content with [conventional-changelog](https://github.com/conventional-changelog/conventional-changelog)
4
+
5
+ [![Build Status](https://github.com/myparcelnl/release-notes-generator/workflows/Test/badge.svg)](https://github.com/myparcelnl/release-notes-generator/actions?query=workflow%3ATest+branch%3Amaster) [![npm latest version](https://img.shields.io/npm/v/@myparcel-dev/semantic-release-release-notes-generator/latest.svg)](https://www.npmjs.com/package/@myparcel-dev/semantic-release-release-notes-generator)
6
+
7
+ | Step | Description |
8
+ |-----------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------|
9
+ | `generateNotes` | Generate release notes for the commits added since the last release with [conventional-changelog](https://github.com/conventional-changelog/conventional-changelog). |
10
+
11
+ ## Install
12
+
13
+ ```bash
14
+ $ npm install @myparcel-dev/semantic-release-release-notes-generator -D
15
+ ```
16
+
17
+ ## Usage
18
+
19
+ The plugin can be configured in the [**semantic-release** configuration file](https://github.com/semantic-release/semantic-release/blob/master/docs/usage/configuration.md#configuration):
20
+
21
+ ```json
22
+ {
23
+ "plugins": [
24
+ ["@semantic-release/commit-analyzer", {
25
+ "preset": "angular",
26
+ "parserOpts": {
27
+ "noteKeywords": ["BREAKING CHANGE", "BREAKING CHANGES", "BREAKING"]
28
+ }
29
+ }],
30
+ ["@semantic-release/release-notes-generator", {
31
+ "preset": "angular",
32
+ "parserOpts": {
33
+ "noteKeywords": ["BREAKING CHANGE", "BREAKING CHANGES", "BREAKING"]
34
+ },
35
+ "writerOpts": {
36
+ "commitsSort": ["subject", "scope"]
37
+ }
38
+ }]
39
+ ]
40
+ }
41
+ ```
42
+
43
+ With this example:
44
+ - the commits that contains `BREAKING CHANGE`, `BREAKING CHANGES` or `BREAKING` in their body will be considered breaking changes (by default the [angular 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`)
45
+ - the commits will be sorted in the changelog by `subject` then `scope` (by default the [angular preset](https://github.com/conventional-changelog/conventional-changelog/blob/master/packages/conventional-changelog-angular/index.js#L90) sort the commits in the changelog by `scope` then `subject`)
46
+
47
+ ## Configuration
48
+
49
+ ### Options
50
+
51
+ | Option | Description | Default |
52
+ |------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------|
53
+ | `preset` | [conventional-changelog](https://github.com/conventional-changelog/conventional-changelog) preset (possible values: [`angular`](https://github.com/conventional-changelog/conventional-changelog/tree/master/packages/conventional-changelog-angular), [`atom`](https://github.com/conventional-changelog/conventional-changelog/tree/master/packages/conventional-changelog-atom), [`codemirror`](https://github.com/conventional-changelog/conventional-changelog/tree/master/packages/conventional-changelog-codemirror), [`ember`](https://github.com/conventional-changelog/conventional-changelog/tree/master/packages/conventional-changelog-ember), [`eslint`](https://github.com/conventional-changelog/conventional-changelog/tree/master/packages/conventional-changelog-eslint), [`express`](https://github.com/conventional-changelog/conventional-changelog/tree/master/packages/conventional-changelog-express), [`jquery`](https://github.com/conventional-changelog/conventional-changelog/tree/master/packages/conventional-changelog-jquery), [`jshint`](https://github.com/conventional-changelog/conventional-changelog/tree/master/packages/conventional-changelog-jshint), [`conventionalcommits`](https://github.com/conventional-changelog/conventional-changelog/tree/master/packages/conventional-changelog-conventionalcommits)). | [`angular`](https://github.com/conventional-changelog/conventional-changelog/tree/master/packages/conventional-changelog-angular) |
54
+ | `config` | NPM package name of a custom [conventional-changelog](https://github.com/conventional-changelog/conventional-changelog) preset. | - |
55
+ | `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. | - |
56
+ | `writerOpts` | Additional [conventional-commits-writer](https://github.com/conventional-changelog/conventional-changelog/tree/master/packages/conventional-changelog-writer#options) 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. | - |
57
+ | `host` | The host used to generate links to issues and commits. See [conventional-changelog-writer#host](https://github.com/conventional-changelog/conventional-changelog/tree/master/packages/conventional-changelog-writer#host). | The host from the [`repositoryurl` option](https://github.com/semantic-release/semantic-release/blob/master/docs/usage/configuration.md#repositoryurl). |
58
+ | `linkCompare` | Whether to include a link to compare changes since previous release in the release note. | `true` |
59
+ | `linkReferences` | Whether to include a link to issues and commits in the release note. See [conventional-changelog-writer#linkreferences](https://github.com/conventional-changelog/conventional-changelog/tree/master/packages/conventional-changelog-writer#linkreferences). | `true` |
60
+ | `commit` | Keyword used to generate commit links (formatted as `<host>/<owner>/<repository>/<commit>/<commit_sha>`). See [conventional-changelog-writer#commit](https://github.com/conventional-changelog/conventional-changelog/tree/master/packages/conventional-changelog-writer#commit). | `commits` for Bitbucket repositories, `commit` otherwise |
61
+ | `issue` | Keyword used to generate issue links (formatted as `<host>/<owner>/<repository>/<issue>/<issue_number>`). See [conventional-changelog-writer#issue](https://github.com/conventional-changelog/conventional-changelog/tree/master/packages/conventional-changelog-writer#issue). | `issue` for Bitbucket repositories, `issues` otherwise |
62
+ | `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). | - |
63
+
64
+ **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`)
65
+
66
+ **Note**: `config` will be overwritten by the values of `preset`. You should use either `preset` or `config`, but not both.
67
+
68
+ **Note**: Individual properties of `parserOpts` and `writerOpts` will override ones loaded with an explicitly set `preset` or `config`. If `preset` or `config` are not set, only the properties set in `parserOpts` and `writerOpts` will be used.
69
+
70
+ **Note**: For presets that expects a configuration object, such as [`conventionalcommits`](https://github.com/conventional-changelog/conventional-changelog/tree/master/packages/conventional-changelog-conventionalcommits), the `presetConfig` option **must** be set.
package/index.js ADDED
@@ -0,0 +1,119 @@
1
+ const fs = require('fs');
2
+ const fspath = require('path');
3
+ const {format} = require('url');
4
+ const {find, merge} = require('lodash');
5
+ const getStream = require('get-stream');
6
+ const intoStream = require('into-stream');
7
+ const parser = require('conventional-commits-parser').sync;
8
+ const writer = require('conventional-changelog-writer');
9
+ const filter = require('conventional-commits-filter');
10
+ const readPkgUp = require('read-pkg-up');
11
+ const debug = require('debug')('semantic-release:release-notes-generator');
12
+ const loadChangelogConfig = require('./lib/load-changelog-config.js');
13
+ const HOSTS_CONFIG = require('./lib/hosts-config.js');
14
+
15
+ /**
16
+ * Generate the changelog for all the commits in `options.commits`.
17
+ *
18
+ * @param {Object} pluginConfig The plugin configuration.
19
+ * @param {String} pluginConfig.preset conventional-changelog preset ('angular', 'atom', 'codemirror', 'ember', 'eslint', 'express', 'jquery', 'jscs', 'jshint').
20
+ * @param {String} pluginConfig.config Requierable npm package with a custom conventional-changelog preset
21
+ * @param {Object} pluginConfig.parserOpts Additional `conventional-changelog-parser` options that will overwrite ones loaded by `preset` or `config`.
22
+ * @param {Object} pluginConfig.writerOpts Additional `conventional-changelog-writer` options that will overwrite ones loaded by `preset` or `config`.
23
+ * @param {String} pluginConfig.header Path to a text file appended to the head of the release notes.
24
+ * @param {Object} context The semantic-release context.
25
+ * @param {Array<Object>} context.commits The commits to analyze.
26
+ * @param {Object} context.lastRelease The last release with `gitHead` corresponding to the commit hash used to make the last release and `gitTag` corresponding to the git tag associated with `gitHead`.
27
+ * @param {Object} context.nextRelease The next release with `gitHead` corresponding to the commit hash used to make the release, the release `version` and `gitTag` corresponding to the git tag associated with `gitHead`.
28
+ * @param {Object} context.options.repositoryUrl The git repository URL.
29
+ *
30
+ * @returns {String} The changelog for all the commits in `context.commits`.
31
+ */
32
+ async function generateNotes(pluginConfig, context) {
33
+ const {commits, lastRelease, nextRelease, options, cwd} = context;
34
+ const repositoryUrl = options.repositoryUrl.replace(/\.git$/i, '');
35
+ const {parserOpts, writerOpts} = await loadChangelogConfig(pluginConfig, context);
36
+
37
+ const [match, auth, host, path] = /^(?!.+:\/\/)(?:(?<auth>.*)@)?(?<host>.*?):(?<path>.*)$/.exec(repositoryUrl) || [];
38
+ let {hostname, port, pathname, protocol} = new URL(
39
+ match ? `ssh://${auth ? `${auth}@` : ''}${host}/${path}` : repositoryUrl
40
+ );
41
+ port = protocol.includes('ssh') ? '' : port;
42
+ protocol = protocol && /http[^s]/.test(protocol) ? 'http' : 'https';
43
+ const [, owner, repository] = /^\/(?<owner>[^/]+)?\/?(?<repository>.+)?$/.exec(pathname);
44
+
45
+ const {issue, commit, referenceActions, issuePrefixes} =
46
+ find(HOSTS_CONFIG, (conf) => conf.hostname === hostname) || HOSTS_CONFIG.default;
47
+ const parsedCommits = filter(
48
+ commits
49
+ .filter(({message, hash}) => {
50
+ if (!message.trim()) {
51
+ debug('Skip commit %s with empty message', hash);
52
+ return false;
53
+ }
54
+
55
+ return true;
56
+ })
57
+ .map((rawCommit) => ({
58
+ ...rawCommit,
59
+ ...parser(rawCommit.message, {referenceActions, issuePrefixes, ...parserOpts}),
60
+ }))
61
+ );
62
+ const previousTag = lastRelease.gitTag || lastRelease.gitHead;
63
+ const currentTag = nextRelease.gitTag || nextRelease.gitHead;
64
+ const {host: hostConfig, linkCompare, linkReferences, commit: commitConfig, issue: issueConfig} = pluginConfig;
65
+ const changelogContext = merge(
66
+ {
67
+ version: nextRelease.version,
68
+ host: format({protocol, hostname, port}),
69
+ owner,
70
+ repository,
71
+ previousTag,
72
+ currentTag,
73
+ linkCompare: currentTag && previousTag,
74
+ issue,
75
+ commit,
76
+ packageData: ((await readPkgUp({normalize: false, cwd})) || {}).packageJson,
77
+ },
78
+ {host: hostConfig, linkCompare, linkReferences, commit: commitConfig, issue: issueConfig}
79
+ );
80
+
81
+ debug('version: %o', changelogContext.version);
82
+ debug('host: %o', changelogContext.hostname);
83
+ debug('owner: %o', changelogContext.owner);
84
+ debug('repository: %o', changelogContext.repository);
85
+ debug('previousTag: %o', changelogContext.previousTag);
86
+ debug('currentTag: %o', changelogContext.currentTag);
87
+ debug('host: %o', changelogContext.host);
88
+ debug('linkReferences: %o', changelogContext.linkReferences);
89
+ debug('issue: %o', changelogContext.issue);
90
+ debug('commit: %o', changelogContext.commit);
91
+
92
+ let result = await getStream(intoStream.object(parsedCommits).pipe(writer(changelogContext, writerOpts)));
93
+
94
+ if ('header' in pluginConfig) {
95
+ const headerOpt = pluginConfig.header;
96
+
97
+ if (headerOpt === fspath.basename(headerOpt)) {
98
+ result = headerOpt + '\n' + result;
99
+ } else if (fs.existsSync(pluginConfig.header)) {
100
+ const header = fs.readFileSync(headerOpt, {encoding: 'utf8'});
101
+ result = header + '\n' + result;
102
+ }
103
+ }
104
+
105
+ if ('footer' in pluginConfig) {
106
+ const footerOpt = pluginConfig.footer;
107
+
108
+ if (footerOpt === fspath.basename(footerOpt)) {
109
+ result = result + '\n' + footerOpt;
110
+ } else if (fs.existsSync(pluginConfig.footer)) {
111
+ const footer = fs.readFileSync(footerOpt, {encoding: 'utf8'});
112
+ result = result + '\n' + footer;
113
+ }
114
+ }
115
+
116
+ return result;
117
+ }
118
+
119
+ module.exports = {generateNotes};
@@ -0,0 +1,55 @@
1
+ module.exports = {
2
+ github: {
3
+ hostname: 'github.com',
4
+ issue: 'issues',
5
+ commit: 'commit',
6
+ referenceActions: ['close', 'closes', 'closed', 'fix', 'fixes', 'fixed', 'resolve', 'resolves', 'resolved'],
7
+ issuePrefixes: ['#', 'gh-'],
8
+ },
9
+ bitbucket: {
10
+ hostname: 'bitbucket.org',
11
+ issue: 'issue',
12
+ commit: 'commits',
13
+ referenceActions: [
14
+ 'close',
15
+ 'closes',
16
+ 'closed',
17
+ 'closing',
18
+ 'fix',
19
+ 'fixes',
20
+ 'fixed',
21
+ 'fixing',
22
+ 'resolve',
23
+ 'resolves',
24
+ 'resolved',
25
+ 'resolving',
26
+ ],
27
+ issuePrefixes: ['#'],
28
+ },
29
+ gitlab: {
30
+ hostname: 'gitlab.com',
31
+ issue: 'issues',
32
+ commit: 'commit',
33
+ referenceActions: ['close', 'closes', 'closed', 'closing', 'fix', 'fixes', 'fixed', 'fixing'],
34
+ issuePrefixes: ['#'],
35
+ },
36
+ default: {
37
+ issue: 'issues',
38
+ commit: 'commit',
39
+ referenceActions: [
40
+ 'close',
41
+ 'closes',
42
+ 'closed',
43
+ 'closing',
44
+ 'fix',
45
+ 'fixes',
46
+ 'fixed',
47
+ 'fixing',
48
+ 'resolve',
49
+ 'resolves',
50
+ 'resolved',
51
+ 'resolving',
52
+ ],
53
+ issuePrefixes: ['#', 'gh-'],
54
+ },
55
+ };
@@ -0,0 +1,42 @@
1
+ const {promisify} = require('util');
2
+ const {isPlainObject} = require('lodash');
3
+ const importFrom = require('import-from');
4
+ const conventionalChangelogAngular = require('conventional-changelog-angular');
5
+
6
+ /**
7
+ * Load `conventional-changelog-parser` options. Handle presets that return either a `Promise<Array>` or a `Promise<Function>`.
8
+ *
9
+ * @param {Object} pluginConfig The plugin configuration.
10
+ * @param {Object} pluginConfig.preset conventional-changelog preset ('angular', 'atom', 'codemirror', 'ember', 'eslint', 'express', 'jquery', 'jscs', 'jshint')
11
+ * @param {string} pluginConfig.config Requierable npm package with a custom conventional-changelog preset
12
+ * @param {Object} pluginConfig.parserOpts Additionnal `conventional-changelog-parser` options that will overwrite ones loaded by `preset` or `config`.
13
+ * @param {Object} pluginConfig.writerOpts Additionnal `conventional-changelog-writer` options that will overwrite ones loaded by `preset` or `config`.
14
+ * @param {Object} context The semantic-release context.
15
+ * @param {Array<Object>} context.commits The commits to analyze.
16
+ * @param {String} context.cwd The current working directory.
17
+ *
18
+ * @return {Promise<Object>} a `Promise` that resolve to the `conventional-changelog-core` config.
19
+ */
20
+ module.exports = async ({preset, config, parserOpts, writerOpts, presetConfig}, {cwd}) => {
21
+ let loadedConfig;
22
+
23
+ if (preset) {
24
+ const presetPackage = `conventional-changelog-${preset.toLowerCase()}`;
25
+ loadedConfig = importFrom.silent(__dirname, presetPackage) || importFrom(cwd, presetPackage);
26
+ } else if (config) {
27
+ loadedConfig = importFrom.silent(__dirname, config) || importFrom(cwd, config);
28
+ } else {
29
+ loadedConfig = conventionalChangelogAngular;
30
+ }
31
+
32
+ loadedConfig = await (typeof loadedConfig === 'function'
33
+ ? isPlainObject(presetConfig)
34
+ ? loadedConfig(presetConfig)
35
+ : promisify(loadedConfig)()
36
+ : loadedConfig);
37
+
38
+ return {
39
+ parserOpts: {...loadedConfig.parserOpts, ...parserOpts},
40
+ writerOpts: {...loadedConfig.writerOpts, ...writerOpts},
41
+ };
42
+ };
package/package.json ADDED
@@ -0,0 +1,107 @@
1
+ {
2
+ "name": "@myparcel-dev/semantic-release-release-notes-generator",
3
+ "description": "semantic-release plugin to generate changelog content with conventional-changelog",
4
+ "version": "10.1.1",
5
+ "author": "Pierre Vanduynslager (https://twitter.com/@pvdlg_)",
6
+ "bugs": {
7
+ "url": "https://github.com/semantic-release/release-notes-generator/issues"
8
+ },
9
+ "contributors": [
10
+ "Stephan Bönnemann <stephan@boennemann.me> (http://boennemann.me)",
11
+ "Gregor Martynus (https://twitter.com/gr2m)"
12
+ ],
13
+ "dependencies": {
14
+ "conventional-changelog-angular": "^5.0.0",
15
+ "conventional-changelog-writer": "^5.0.0",
16
+ "conventional-commits-filter": "^2.0.0",
17
+ "conventional-commits-parser": "^3.2.3",
18
+ "debug": "^4.0.0",
19
+ "get-stream": "^6.0.0",
20
+ "import-from": "^4.0.0",
21
+ "into-stream": "^6.0.0",
22
+ "lodash": "^4.17.4",
23
+ "read-pkg-up": "^7.0.0"
24
+ },
25
+ "devDependencies": {
26
+ "ava": "5.1.0",
27
+ "conventional-changelog-atom": "2.0.8",
28
+ "conventional-changelog-conventionalcommits": "5.0.0",
29
+ "conventional-changelog-ember": "2.0.9",
30
+ "conventional-changelog-eslint": "3.0.9",
31
+ "conventional-changelog-express": "2.0.6",
32
+ "conventional-changelog-jshint": "2.0.9",
33
+ "escape-string-regexp": "4.0.0",
34
+ "fs-extra": "11.1.1",
35
+ "nyc": "15.1.0",
36
+ "proxyquire": "2.1.3",
37
+ "semantic-release": "21.0.1",
38
+ "sinon": "15.0.3",
39
+ "tempy": "1.0.1",
40
+ "xo": "0.39.1"
41
+ },
42
+ "engines": {
43
+ "node": ">=14.17"
44
+ },
45
+ "files": [
46
+ "lib",
47
+ "index.js"
48
+ ],
49
+ "homepage": "https://github.com/semantic-release/release-notes-generator#readme",
50
+ "keywords": [
51
+ "changelog",
52
+ "conventional-changelog",
53
+ "conventional-commits",
54
+ "github",
55
+ "publish",
56
+ "release",
57
+ "release-note-generator",
58
+ "semantic-release"
59
+ ],
60
+ "license": "MIT",
61
+ "main": "index.js",
62
+ "nyc": {
63
+ "include": [
64
+ "lib/**/*.js",
65
+ "index.js"
66
+ ],
67
+ "reporter": [
68
+ "json",
69
+ "text",
70
+ "html"
71
+ ],
72
+ "all": true
73
+ },
74
+ "peerDependencies": {
75
+ "semantic-release": ">=18.0.0-beta.1"
76
+ },
77
+ "prettier": {
78
+ "printWidth": 120,
79
+ "trailingComma": "es5"
80
+ },
81
+ "publishConfig": {
82
+ "access": "public"
83
+ },
84
+ "repository": {
85
+ "type": "git",
86
+ "url": "https://github.com/myparcelnl/release-notes-generator.git"
87
+ },
88
+ "scripts": {
89
+ "lint": "xo",
90
+ "pretest": "npm run lint",
91
+ "semantic-release": "semantic-release",
92
+ "test": "nyc ava -v",
93
+ "test:ci": "nyc ava -v"
94
+ },
95
+ "xo": {
96
+ "prettier": true,
97
+ "space": true,
98
+ "rules": {
99
+ "unicorn/string-content": "off"
100
+ }
101
+ },
102
+ "renovate": {
103
+ "extends": [
104
+ "github>semantic-release/.github"
105
+ ]
106
+ }
107
+ }