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

Ensure CHANGELOG.md has correct version when git.tagName is not present #48

Merged
merged 1 commit into from
Apr 27, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 3 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ module.exports = class LernaChangelogGeneratorPlugin extends Plugin {

get nextVersion() {
let { version } = this.config.getContext();
let nextVersion = this.getTagNameFromVersion(version);

let tagName = this.config.getContext('git.tagName');
let nextVersion = tagName ? format(tagName, { version }) : version;

return nextVersion;
}
Expand All @@ -33,12 +35,6 @@ module.exports = class LernaChangelogGeneratorPlugin extends Plugin {
return this.changelog;
}

getTagNameFromVersion(version) {
let tagName = this.config.getContext('git.tagName');

return format(tagName, { version });
}

async getTagForHEAD() {
try {
return await this.exec('git describe --tags --abbrev=0', { options: { write: false } });
Expand Down
6 changes: 5 additions & 1 deletion test.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ test('it invokes lerna-changelog', async (t) => {
});

test('it honors custom git.tagName formatting', async (t) => {
let plugin = buildPlugin();
let infile = tmp.fileSync().name;
let plugin = buildPlugin({ infile });

plugin.config.setContext({ git: { tagName: 'v${version}' } });

Expand All @@ -105,6 +106,9 @@ test('it honors custom git.tagName formatting', async (t) => {
['git describe --tags --abbrev=0', { write: false }],
[`${LERNA_PATH} --next-version=Unreleased --from=v1.0.0`, { write: false }],
]);

const changelog = fs.readFileSync(infile, { encoding: 'utf8' });
t.is(changelog, `### v1.0.1 (2020-03-18)\n\nThe changelog\n\n`);
});

test('it sets the changelog without version information onto the config', async (t) => {
Expand Down