diff --git a/README.md b/README.md index 9974c6b..8b2712d 100644 --- a/README.md +++ b/README.md @@ -123,6 +123,46 @@ For example, you can use the following option to include merge commits into chan } ``` +### `parserOpts` + +Default value: `undefined` + +Options for +[`conventional-commits-parser`](https://github.com/conventional-changelog/conventional-changelog/tree/master/packages/conventional-commits-parser#api). +For example, you can use the following option to set the merge pattern during parsing the commit message: + +```json +{ + "plugins": { + "@release-it/conventional-changelog": { + "parserOpts": { + "mergePattern": /^Merge pull request #(\d+) from (.*)$/ + } + } + } +} +``` + +### `writerOpts` + +Default value: `undefined` + +Options for +[`conventional-changelog-writer`](https://github.com/conventional-changelog/conventional-changelog/tree/master/packages/conventional-changelog-writer#api). +For example, you can use the following option to group the commits by 'scope' instead of 'type' by default. + +```json +{ + "plugins": { + "@release-it/conventional-changelog": { + "writerOpts": { + "groupBy:" "scope" + } + } + } +} +``` + ## GitHub Actions When using this plugin in a GitHub Action, make sure to set diff --git a/index.js b/index.js index cfc0922..7d05013 100644 --- a/index.js +++ b/index.js @@ -69,10 +69,13 @@ class ConventionalChangelog extends Plugin { const context = Object.assign({ version, previousTag, currentTag }, this.options.context); const debug = this.config.isDebug ? this.debug : null; const gitRawCommitsOpts = Object.assign({ debug }, this.options.gitRawCommitsOpts); + const { parserOpts, writerOpts } = options delete options.context; delete options.gitRawCommitsOpts; - this.debug('conventionalChangelog', { options, context, gitRawCommitsOpts }); - return conventionalChangelog(options, context, gitRawCommitsOpts); + delete options.parserOpts; + delete options.writerOpts; + this.debug('conventionalChangelog', { options, context, gitRawCommitsOpts, parserOpts, writerOpts }); + return conventionalChangelog(options, context, gitRawCommitsOpts, parserOpts, writerOpts); } generateChangelog(options) { diff --git a/test.js b/test.js index 60053b5..89f2a30 100644 --- a/test.js +++ b/test.js @@ -167,3 +167,66 @@ test('should not write infile in dry run', async t => { assert.strictEqual(spy.callCount, 0); assert.throws(() => fs.readFileSync(infile), /no such file/); }); + +test('should pass only parserOpts', async t => { + conventionalChangelog.resetHistory(); + const parserOpts = { + mergePattern: /^Merge pull request #(\d+) from (.*)$/, + mergeCorrespondence: ['id', 'source'] + }; + const options = { [namespace]: { preset, parserOpts } }; + const plugin = factory(Plugin, { namespace, options }); + await runTasks(plugin); + const args = conventionalChangelog.args[0]; + assert.deepStrictEqual(args[0], { releaseCount: 1, preset: 'angular', tagPrefix: '' }); + assert.deepStrictEqual(args[1], { version: '1.1.0', currentTag: null, previousTag: undefined }); + assert.deepStrictEqual(args[2], { debug: null }); + assert.deepStrictEqual(args[3], { + mergePattern: /^Merge pull request #(\d+) from (.*)$/, + mergeCorrespondence: ['id', 'source'] + }); + assert.deepStrictEqual(args[4], undefined) +}); + +test('should pass only writerOpts', async t => { + conventionalChangelog.resetHistory(); + const writerOpts = { + groupBy: 'scope' + }; + const options = { [namespace]: { preset, writerOpts } }; + const plugin = factory(Plugin, { namespace, options }); + await runTasks(plugin); + const args = conventionalChangelog.args[0]; + assert.deepStrictEqual(args[0], { releaseCount: 1, preset: 'angular', tagPrefix: '' }); + assert.deepStrictEqual(args[1], { version: '1.1.0', currentTag: null, previousTag: undefined }); + assert.deepStrictEqual(args[2], { debug: null }); + assert.deepStrictEqual(args[3], undefined) + assert.deepStrictEqual(args[4], { + groupBy: 'scope' + }); +}); + +test('should pass parserOpts and writerOpts', async t => { + conventionalChangelog.resetHistory(); + const parserOpts = { + mergePattern: /^Merge pull request #(\d+) from (.*)$/, + mergeCorrespondence: ['id', 'source'] + }; + const writerOpts = { + groupBy: 'type' + }; + const options = { [namespace]: { preset, parserOpts, writerOpts } }; + const plugin = factory(Plugin, { namespace, options }); + await runTasks(plugin); + const args = conventionalChangelog.args[0]; + assert.deepStrictEqual(args[0], { releaseCount: 1, preset: 'angular', tagPrefix: '' }); + assert.deepStrictEqual(args[1], { version: '1.1.0', currentTag: null, previousTag: undefined }); + assert.deepStrictEqual(args[2], { debug: null }); + assert.deepStrictEqual(args[3], { + mergePattern: /^Merge pull request #(\d+) from (.*)$/, + mergeCorrespondence: ['id', 'source'] + }); + assert.deepStrictEqual(args[4], { + groupBy: 'type' + }); +});