Skip to content

Commit

Permalink
Pass 'parserOpts' and 'writerOpts' to conventional-changelog-core (#32)
Browse files Browse the repository at this point in the history
* Pass 'parserOpts' and 'writerOpts' to conventional-changelog-core

* Using a different groupBy value on writerOpts tests

* Update README.md with new parserOpts and writerOpts options

* Update README.md with correct links for changelog-core docs of parserOpts and writerOpts options
  • Loading branch information
rondymesquita authored Aug 20, 2021
1 parent bf19b4e commit 69aa6b0
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 2 deletions.
40 changes: 40 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
63 changes: 63 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
});
});

0 comments on commit 69aa6b0

Please sign in to comment.