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

Fix: Don't update changelog when --no-increment flag is set #23

Merged
merged 1 commit into from
Mar 20, 2022
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ class KeepAChangelog extends Plugin {
}

getChangelog(latestVersion) {
const { isIncrement } = this.config;
// Return the unchanged changelog content when no increment is made
if (!isIncrement) {
return this.changelogContent;
}

const { changelog } = this.getContext();
if (changelog) return changelog;

Expand Down Expand Up @@ -94,8 +100,8 @@ class KeepAChangelog extends Plugin {

beforeRelease() {
const { addUnreleased, keepUnreleased, addVersionUrl } = this;
const { isDryRun } = this.config;
if (isDryRun || keepUnreleased) return;
const { isDryRun, isIncrement } = this.config;
if (isDryRun || keepUnreleased || !isIncrement) return;
const { version } = this.getContext();
const formattedDate = getFormattedDate();
const unreleasedTitle = addUnreleased ? this.unreleasedTitle + this.EOL + this.EOL : '';
Expand Down
7 changes: 7 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ test('should throw for empty "unreleased" section', async t => {
await assert.rejects(runTasks(plugin), /There are no entries under "Unreleased" section in CHANGELOG-EMPTY\.md/);
});

test('should not throw for empty "unreleased" section when no-increment flag is set', async t => {
const options = { 'increment': false, [namespace]: { filename: 'CHANGELOG-EMPTY.md' } };
const plugin = factory(Plugin, { namespace, options });
await runTasks(plugin);
assert.equal(plugin.getChangelog(), readFile('./CHANGELOG-EMPTY.md'))
});

test('should throw for missing section for previous release', async t => {
const options = { [namespace]: { filename: 'CHANGELOG-MISSING.md' } };
const plugin = factory(Plugin, { namespace, options });
Expand Down