Skip to content

Commit

Permalink
fix(conventional-commits): Preserve tag prefix in fixed changelog com…
Browse files Browse the repository at this point in the history
…parison links

Refs #2197
  • Loading branch information
evocateur committed Jul 24, 2019
1 parent 8adeac1 commit 11cf6d2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
Expand Up @@ -377,15 +377,15 @@ describe("conventional-commits", () => {
]);

expect(leafChangelog.newEntry.trimRight()).toMatchInlineSnapshot(`
## [1.0.1](/compare/dragons-are-awesome1.0.0...1.0.1) (YYYY-MM-DD)
## [1.0.1](/compare/dragons-are-awesome1.0.0...dragons-are-awesome1.0.1) (YYYY-MM-DD)
### Bug Fixes
* A second commit for our CHANGELOG ([SHA](https://github.com/lerna/conventional-commits-fixed/commit/SHA))
`);
expect(rootChangelog.newEntry.trimRight()).toMatchInlineSnapshot(`
## [1.0.1](/compare/dragons-are-awesome1.0.0...1.0.1) (YYYY-MM-DD)
## [1.0.1](/compare/dragons-are-awesome1.0.0...dragons-are-awesome1.0.1) (YYYY-MM-DD)
### Bug Fixes
Expand All @@ -409,7 +409,7 @@ describe("conventional-commits", () => {

// second commit should not show up again
expect(lastRootChangelog.newEntry.trimRight()).toMatchInlineSnapshot(`
## [1.0.2](/compare/dragons-are-awesome1.0.1...1.0.2) (YYYY-MM-DD)
## [1.0.2](/compare/dragons-are-awesome1.0.1...dragons-are-awesome1.0.2) (YYYY-MM-DD)
### Bug Fixes
Expand Down
12 changes: 9 additions & 3 deletions core/conventional-commits/lib/update-changelog.js
Expand Up @@ -11,12 +11,12 @@ const readExistingChangelog = require("./read-existing-changelog");

module.exports = updateChangelog;

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

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

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

if (type === "root") {
context = { version };
context.version = version;

// preserve tagPrefix because cc-core can't find the currentTag otherwise
context.currentTag = `${tagPrefix}${version}`;

// root changelogs are only enabled in fixed mode, and need the proper tag prefix
options.tagPrefix = tagPrefix;
Expand All @@ -45,6 +48,9 @@ function updateChangelog(pkg, type, { changelogPreset, rootPath, tagPrefix, vers
} else {
// only fixed mode can have a custom tag prefix
options.tagPrefix = tagPrefix;

// preserve tagPrefix because cc-core can't find the currentTag otherwise
context.currentTag = `${tagPrefix}${pkg.version}`;
}
}

Expand Down

0 comments on commit 11cf6d2

Please sign in to comment.