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

Pass 'parserOpts' and 'writerOpts' to conventional-changelog-core #32

Merged
merged 4 commits into from
Aug 20, 2021
Merged
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
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'
});
});