Skip to content

Commit bda85ae

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 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 bda85ae

File tree

2 files changed

+50
-8
lines changed

2 files changed

+50
-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: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,3 +451,48 @@ test('should generate changelog with origin urls', async () => {
451451
const baz = commit('feat', 'baz', url);
452452
assert.match(nl(changelog), new RegExp('^' + title + fixes + bar + features + baz + '$'));
453453
});
454+
455+
test('should apply custom issuePrefixes from parserOpts', async () => {
456+
setup();
457+
458+
sh.exec(`git tag 1.0.0`);
459+
460+
// Create a commit with a custom issue reference in the body
461+
sh.ShellString('bar').toEnd('bar');
462+
sh.exec(`git add bar`);
463+
// Use a commit with a custom issue prefix in the footer
464+
sh.exec(`git commit -m "fix(bar): fix bar
465+
466+
Refs: XYZ-123"`);
467+
468+
// Test 1: WITHOUT custom issuePrefixes, the parser won't recognize XYZ-123
469+
// and the changelog won't show any issue reference
470+
{
471+
const options = getOptions({ preset });
472+
const { changelog } = await runTasks(...options);
473+
// Without issuePrefixes: ['XYZ-'], the parser won't detect XYZ-123 as an issue
474+
// so no "closes" reference should appear
475+
assert.doesNotMatch(changelog, /closes/);
476+
}
477+
478+
// Reset and create the same commit again
479+
sh.exec(`git tag 1.0.1`);
480+
sh.ShellString('baz').toEnd('baz');
481+
sh.exec(`git add baz`);
482+
sh.exec(`git commit -m "fix(baz): fix baz
483+
484+
Refs: XYZ-456"`);
485+
486+
// Test 2: WITH custom issuePrefixes, the parser recognizes XYZ-456 as an issue
487+
// The angular preset outputs issues with # prefix, so we check for #456
488+
{
489+
const parserOpts = {
490+
issuePrefixes: ['XYZ-']
491+
};
492+
const options = getOptions({ preset, parserOpts });
493+
const { changelog } = await runTasks(...options);
494+
// With issuePrefixes: ['XYZ-'], the parser detects XYZ-456 as issue 456
495+
// The angular writer template outputs it as #456 (hardcoded in template)
496+
assert.match(changelog, /closes.*#456/);
497+
}
498+
});

0 commit comments

Comments
 (0)