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

additionalChangelog CLI option #154

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,10 @@ Only applies when the changelog is in `README.md` and a `CHANGELOG_OLD.md` exist

If you want the release script to add a new empty placeholder to the changelog after a release, this option is for you. By default, this is disabled.

#### Add additional entries to the release changelog (`--additionalChangelog` or `--additional-changelog`)

If you want the release script to add some more entry/entries to the changelog for the release. To add multiple just separate them using `\n` so f.e. `* Entry 1\n* Entry 2`.By default this does not add anything.

### `package` plugin options

#### Don't synchronize the lockfile (`--no-update-lockfile`)
Expand Down
90 changes: 90 additions & 0 deletions packages/plugin-changelog/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ stuff
### Subsection 2
* New entry 4
* New entry 5`,
changelog_testParseAdditionalChangelog1Without: `## **WORK IN PROGRESS** · Doomsday release
* New entry 1
* New entry 2`,
changelog_testParseAdditionalChangelog1With: `## **WORK IN PROGRESS** · Doomsday release
* New entry 1
* New entry 2
* first Changelog entry added via cli-option
* another CLI-Option Changelog entry`,
};

describe("Changelog plugin", () => {
Expand Down Expand Up @@ -266,6 +274,88 @@ ${fixtures.changelog_subsectionsParse2}`,
* New entry 2`);
});

it("parses all changelog entries correctly if additionalChangelog is set", async () => {
const changelogPlugin = new ChangelogPlugin();
const context = createMockContext({
plugins: [changelogPlugin],
cwd: testFSRoot,
argv: {
additionalChangelog: '* first Changelog entry added via cli-option\n* another CLI-Option Changelog entry',
}
});

await testFS.create({
"CHANGELOG.md": `${fixtures.changelog_testParseHeader}
${fixtures.changelog_testParseAdditionalChangelog1Without}

${fixtures.changelog_testParse2}

${fixtures.changelog_testParse3}`,
});

await changelogPlugin.executeStage(context, DefaultStages.check);
expect(context.errors).toHaveLength(0);

const headline = context.getData<string[]>("changelog_before");
expect(headline).toBe(fixtures.changelog_testParseHeader + "\n");

const entries = context.getData<string[]>("changelog_entries");
expect(entries).toEqual([
fixtures.changelog_testParseAdditionalChangelog1With,
fixtures.changelog_testParse2,
fixtures.changelog_testParse3,
]);

const footer = context.getData<string[]>("changelog_after");
expect(footer).toBe("");

const currentChangelog = context.getData<string[]>("changelog_new");
expect(currentChangelog).toBe(`* New entry 1
* New entry 2
* first Changelog entry added via cli-option
* another CLI-Option Changelog entry`);
});

it("even if no WIP section exists before", async () => {
const changelogPlugin = new ChangelogPlugin();
const context = createMockContext({
plugins: [changelogPlugin],
cwd: testFSRoot,
argv: {
additionalChangelog: '* first Changelog entry added via cli-option\n* another CLI-Option Changelog entry',
}
});

await testFS.create({
"CHANGELOG.md": `${fixtures.changelog_testParseHeader}
${fixtures.changelog_testParse2}

${fixtures.changelog_testParse3}`,
});

await changelogPlugin.executeStage(context, DefaultStages.check);
expect(context.errors).toHaveLength(0);

const headline = context.getData<string[]>("changelog_before");
expect(headline).toBe(fixtures.changelog_testParseHeader + "\n");

const entries = context.getData<string[]>("changelog_entries");
expect(entries).toEqual([
`## **WORK IN PROGRESS**
* first Changelog entry added via cli-option
* another CLI-Option Changelog entry`,
fixtures.changelog_testParse2,
fixtures.changelog_testParse3,
]);

const footer = context.getData<string[]>("changelog_after");
expect(footer).toBe("");

const currentChangelog = context.getData<string[]>("changelog_new");
expect(currentChangelog).toBe(`* first Changelog entry added via cli-option
* another CLI-Option Changelog entry`);
});

it("Detects final newlines correctly", async () => {
const changelogPlugin = new ChangelogPlugin();
const context = createMockContext({
Expand Down
15 changes: 15 additions & 0 deletions packages/plugin-changelog/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ class ChangelogPlugin implements Plugin {
description: `Add an empty placeholder to the changelog after a release.`,
default: false,
},
additionalChangelog: {
alias: ["additional-changelog"],
type: "string",
description: `Add additional changelog entry/entries to the release.`
}
});
}

Expand Down Expand Up @@ -183,7 +188,17 @@ class ChangelogPlugin implements Plugin {
// But we only output the primary one
const changelogPlaceholder = `${changelogPlaceholderPrefix} ${changelogMarkers[0]}`;

if(context.argv.additionalChangelog) {
let currentChangelogsIndex = entries.findIndex((e) => getPlaceholderRegex().test(e));
if (currentChangelogsIndex == -1) {
entries.unshift(changelogPlaceholder);
currentChangelogsIndex = 0
}
entries[currentChangelogsIndex] += `\n${context.argv.additionalChangelog}`;
}

const currentChangelogs = entries.filter((e) => getPlaceholderRegex().test(e));

switch (currentChangelogs.length) {
case 0:
context.cli.error(
Expand Down