Skip to content

Commit 11cf6d2

Browse files
committed
fix(conventional-commits): Preserve tag prefix in fixed changelog comparison links
Refs #2197
1 parent 8adeac1 commit 11cf6d2

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

core/conventional-commits/__tests__/conventional-commits.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -377,15 +377,15 @@ describe("conventional-commits", () => {
377377
]);
378378

379379
expect(leafChangelog.newEntry.trimRight()).toMatchInlineSnapshot(`
380-
## [1.0.1](/compare/dragons-are-awesome1.0.0...1.0.1) (YYYY-MM-DD)
380+
## [1.0.1](/compare/dragons-are-awesome1.0.0...dragons-are-awesome1.0.1) (YYYY-MM-DD)
381381
382382
383383
### Bug Fixes
384384
385385
* A second commit for our CHANGELOG ([SHA](https://github.com/lerna/conventional-commits-fixed/commit/SHA))
386386
`);
387387
expect(rootChangelog.newEntry.trimRight()).toMatchInlineSnapshot(`
388-
## [1.0.1](/compare/dragons-are-awesome1.0.0...1.0.1) (YYYY-MM-DD)
388+
## [1.0.1](/compare/dragons-are-awesome1.0.0...dragons-are-awesome1.0.1) (YYYY-MM-DD)
389389
390390
391391
### Bug Fixes
@@ -409,7 +409,7 @@ describe("conventional-commits", () => {
409409

410410
// second commit should not show up again
411411
expect(lastRootChangelog.newEntry.trimRight()).toMatchInlineSnapshot(`
412-
## [1.0.2](/compare/dragons-are-awesome1.0.1...1.0.2) (YYYY-MM-DD)
412+
## [1.0.2](/compare/dragons-are-awesome1.0.1...dragons-are-awesome1.0.2) (YYYY-MM-DD)
413413
414414
415415
### Bug Fixes

core/conventional-commits/lib/update-changelog.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ const readExistingChangelog = require("./read-existing-changelog");
1111

1212
module.exports = updateChangelog;
1313

14-
function updateChangelog(pkg, type, { changelogPreset, rootPath, tagPrefix, version }) {
14+
function updateChangelog(pkg, type, { changelogPreset, rootPath, tagPrefix = "v", version }) {
1515
log.silly(type, "for %s at %s", pkg.name, pkg.location);
1616

1717
return getChangelogConfig(changelogPreset, rootPath).then(config => {
1818
const options = {};
19-
let context; // pass as positional because cc-core's merge-config is wack
19+
const context = {}; // pass as positional because cc-core's merge-config is wack
2020

2121
// cc-core mutates input :P
2222
if (config.conventionalChangelog) {
@@ -31,7 +31,10 @@ function updateChangelog(pkg, type, { changelogPreset, rootPath, tagPrefix, vers
3131
const gitRawCommitsOpts = Object.assign({}, options.config.gitRawCommitsOpts);
3232

3333
if (type === "root") {
34-
context = { version };
34+
context.version = version;
35+
36+
// preserve tagPrefix because cc-core can't find the currentTag otherwise
37+
context.currentTag = `${tagPrefix}${version}`;
3538

3639
// root changelogs are only enabled in fixed mode, and need the proper tag prefix
3740
options.tagPrefix = tagPrefix;
@@ -45,6 +48,9 @@ function updateChangelog(pkg, type, { changelogPreset, rootPath, tagPrefix, vers
4548
} else {
4649
// only fixed mode can have a custom tag prefix
4750
options.tagPrefix = tagPrefix;
51+
52+
// preserve tagPrefix because cc-core can't find the currentTag otherwise
53+
context.currentTag = `${tagPrefix}${pkg.version}`;
4854
}
4955
}
5056

0 commit comments

Comments
 (0)