Skip to content

Commit d41e8d1

Browse files
committed
fix: pass parserOpts to both Bumper and ConventionalChangelog
The parserOpts parameter (including issuePrefixes) was being received but not passed correctly to the generators. This caused custom options configured via parserOpts to be ignored since v10.0.2. Changes: - Pass parserOpts as second argument to generator.commits() in the conventionalChangelog wrapper function - Pass parserOpts to Bumper.commits() even when commitsOpts is not set - Add test to verify custom issuePrefixes are applied correctly - Fix test setup to disable GPG tag signing (for envs with gpgSign=true) Note: The angular preset's writer template hardcodes '#' as the issue prefix in the output, so XYZ-123 will be parsed correctly but displayed as release-it#123. Users who want to preserve the original prefix in output need to customize writerOpts. Fixes release-it#133
1 parent 7e53f8c commit d41e8d1

File tree

2 files changed

+52
-8
lines changed

2 files changed

+52
-8
lines changed

index.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,8 @@ async function conventionalChangelog(
3232
generator.context(context);
3333
}
3434

35-
if (Object.keys(gitRawCommitsOpts).length > 0) {
36-
generator.commits(gitRawCommitsOpts);
37-
}
38-
39-
if (Object.keys(parserOpts).length > 0) {
40-
// Parser options are not directly exposed in the new API
41-
// They need to be passed through config or preset
35+
if (Object.keys(gitRawCommitsOpts).length > 0 || Object.keys(parserOpts).length > 0) {
36+
generator.commits(gitRawCommitsOpts, parserOpts);
4237
}
4338

4439
if (Object.keys(writerOpts).length > 0) {
@@ -95,7 +90,9 @@ class ConventionalChangelog extends Plugin {
9590

9691
if (options.tagOpts) bumper.tag(options.tagOpts);
9792

98-
if (options.commitsOpts) bumper.commits(options.commitsOpts, options.parserOpts);
93+
if (options.commitsOpts || options.parserOpts) {
94+
bumper.commits(options.commitsOpts || {}, options.parserOpts);
95+
}
9996

10097
let whatBumpFn;
10198
if (options.whatBump === false) {

test.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ const setup = () => {
5454
const dir = mkTmpDir();
5555
sh.pushd(dir);
5656
sh.exec(`git init .`);
57+
// Disable GPG signing for tags in test repo (may be enabled globally)
58+
sh.exec(`git config tag.gpgSign false`);
5759
add('fix', 'foo');
5860
sh.ShellString('{ "hooks": {} }').toEnd('.release-it.json');
5961
return { dir };
@@ -451,3 +453,48 @@ test('should generate changelog with origin urls', async () => {
451453
const baz = commit('feat', 'baz', url);
452454
assert.match(nl(changelog), new RegExp('^' + title + fixes + bar + features + baz + '$'));
453455
});
456+
457+
test('should apply custom issuePrefixes from parserOpts', async () => {
458+
setup();
459+
460+
sh.exec(`git tag 1.0.0`);
461+
462+
// Create a commit with a custom issue reference in the body
463+
sh.ShellString('bar').toEnd('bar');
464+
sh.exec(`git add bar`);
465+
// Use a commit with a custom issue prefix in the footer
466+
sh.exec(`git commit -m "fix(bar): fix bar
467+
468+
Refs: XYZ-123"`);
469+
470+
// Test 1: WITHOUT custom issuePrefixes, the parser won't recognize XYZ-123
471+
// and the changelog won't show any issue reference
472+
{
473+
const options = getOptions({ preset });
474+
const { changelog } = await runTasks(...options);
475+
// Without issuePrefixes: ['XYZ-'], the parser won't detect XYZ-123 as an issue
476+
// so no "closes" reference should appear
477+
assert.doesNotMatch(changelog, /closes/);
478+
}
479+
480+
// Reset and create the same commit again
481+
sh.exec(`git tag 1.0.1`);
482+
sh.ShellString('baz').toEnd('baz');
483+
sh.exec(`git add baz`);
484+
sh.exec(`git commit -m "fix(baz): fix baz
485+
486+
Refs: XYZ-456"`);
487+
488+
// Test 2: WITH custom issuePrefixes, the parser recognizes XYZ-456 as an issue
489+
// The angular preset outputs issues with # prefix, so we check for #456
490+
{
491+
const parserOpts = {
492+
issuePrefixes: ['XYZ-']
493+
};
494+
const options = getOptions({ preset, parserOpts });
495+
const { changelog } = await runTasks(...options);
496+
// With issuePrefixes: ['XYZ-'], the parser detects XYZ-456 as issue 456
497+
// The angular writer template outputs it as #456 (hardcoded in template)
498+
assert.match(changelog, /closes.*#456/);
499+
}
500+
});

0 commit comments

Comments
 (0)