From 04e160985fdef6dfd14f257c9340f23a11388043 Mon Sep 17 00:00:00 2001 From: Klein Petr Date: Sun, 17 Mar 2024 20:08:05 +0100 Subject: [PATCH 1/5] feat: add skipAuthors (boolean) option test: add test for skipAuthors option test: add test commits fixture --- README.md | 1 + src/commands/default.ts | 1 + src/config.ts | 2 + src/markdown.ts | 4 +- test/__snapshots__/contributors.test.ts.snap | 22 +++++++ test/contributors.test.ts | 69 ++++++++++++++++++++ test/fixtures/commits.ts | 62 ++++++++++++++++++ 7 files changed, 159 insertions(+), 2 deletions(-) create mode 100644 test/__snapshots__/contributors.test.ts.snap create mode 100644 test/contributors.test.ts create mode 100644 test/fixtures/commits.ts diff --git a/README.md b/README.md index fb9ac5e..be24d03 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,7 @@ npx changelogen@latest [...args] [--dir ] - `--dir`: Path to git repository. When not provided, **current working directory** will be used as as default. - `--clean`: Determine if the working directory is clean and if it is not clean, exit. - `--output`: Changelog file name to create or update. Defaults to `CHANGELOG.md` and resolved relative to dir. Use `--no-output` to write to console only. +- `skipAuthors`: Skip contributors section in changelog. - `--bump`: Determine semver change and update version in `package.json`. - `--release`. Bumps version in `package.json` and creates commit and git tags using local `git`. You can disable commit using `--no-commit` and tag using `--no-tag`. You can enable the automatic push of the new tag and release commit to your git repository by adding `--push`. - `--publish`. Publishes package as a new version on `npm`. You will need to set authorisation tokens separately via `.npmrc` or environment variables. diff --git a/src/commands/default.ts b/src/commands/default.ts index 02728d5..04a427f 100644 --- a/src/commands/default.ts +++ b/src/commands/default.ts @@ -25,6 +25,7 @@ export default async function defaultMain(args: Argv) { to: args.to, output: args.output, newVersion: typeof args.r === "string" ? args.r : undefined, + skipAuthors: args.skipAuthors, }); if (args.clean) { diff --git a/src/config.ts b/src/config.ts index 7b6359f..1a7a860 100644 --- a/src/config.ts +++ b/src/config.ts @@ -27,6 +27,7 @@ export interface ChangelogConfig { tagBody?: string; }; excludeAuthors: string[]; + skipAuthors: boolean; } export type ResolvedChangelogConfig = Omit & { @@ -72,6 +73,7 @@ const getDefaultConfig = () => tagBody: "v{{newVersion}}", }, excludeAuthors: [], + skipAuthors: false, }; export async function loadChangelogConfig( diff --git a/src/markdown.ts b/src/markdown.ts index af5fd76..912312c 100644 --- a/src/markdown.ts +++ b/src/markdown.ts @@ -85,7 +85,7 @@ export async function generateMarkDown( const authors = [..._authors.entries()].map((e) => ({ name: e[0], ...e[1] })); - if (authors.length > 0) { + if (authors.length > 0 && !config.skipAuthors) { markdown.push( "", "### " + "❤️ Contributors", @@ -102,7 +102,7 @@ export async function generateMarkDown( }) ); } - + return convert(markdown.join("\n").trim(), true); } diff --git a/test/__snapshots__/contributors.test.ts.snap b/test/__snapshots__/contributors.test.ts.snap new file mode 100644 index 0000000..6e75856 --- /dev/null +++ b/test/__snapshots__/contributors.test.ts.snap @@ -0,0 +1,22 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`contributors > should skip authors 1`] = ` +"## v1.0.0 + + +### 🚀 Enhancements + +- **scope:** Add feature + +### 🩹 Fixes + +- **scope:** Resolve bug + +### 📖 Documentation + +- **scope:** Update documentation + +### 🏡 Chore + +- **scope:** Update dependencies" +`; diff --git a/test/contributors.test.ts b/test/contributors.test.ts new file mode 100644 index 0000000..95e5823 --- /dev/null +++ b/test/contributors.test.ts @@ -0,0 +1,69 @@ +import { describe, expect, test } from "vitest"; +import { loadChangelogConfig, generateMarkDown } from "../src"; +import { testCommits } from "./fixtures/commits"; + +describe("contributors", () => { + test("should include authors", async () => { + const config = await loadChangelogConfig(process.cwd(), { + newVersion: "1.0.0", + }); + const contents = await generateMarkDown(testCommits, config) + + expect(contents).toMatchInlineSnapshot(` + "## v1.0.0 + + + ### 🚀 Enhancements + + - **scope:** Add feature + + ### 🩹 Fixes + + - **scope:** Resolve bug + + ### 📖 Documentation + + - **scope:** Update documentation + + ### 🏡 Chore + + - **scope:** Update dependencies + + ### ❤️ Contributors + + - John Doe ([@brainsucker](http://github.com/brainsucker)) + - Jane Smith + - Alice Johnson + - Bob Williams " + `) + }) + + test("should skip authors", async () => { + const config = await loadChangelogConfig(process.cwd(), { + newVersion: "1.0.0", + skipAuthors: true, + }); + const contents = await generateMarkDown(testCommits, config) + + expect(contents).toMatchInlineSnapshot(` + "## v1.0.0 + + + ### 🚀 Enhancements + + - **scope:** Add feature + + ### 🩹 Fixes + + - **scope:** Resolve bug + + ### 📖 Documentation + + - **scope:** Update documentation + + ### 🏡 Chore + + - **scope:** Update dependencies" + `) + }) +}); diff --git a/test/fixtures/commits.ts b/test/fixtures/commits.ts new file mode 100644 index 0000000..bb2f1f1 --- /dev/null +++ b/test/fixtures/commits.ts @@ -0,0 +1,62 @@ +export const testCommits = [ + { + author: { + name: "John Doe", + email: "john@doe.com", + }, + message: "feat: add feature", + shortHash: "1234", + body: "body", + type: "feat", + description: "add feature", + scope: "scope", + references: [], + authors: [], + isBreaking: false, + }, + { + author: { + name: "Jane Smith", + email: "jane@smith.com", + }, + message: "fix: resolve bug", + shortHash: "5678", + body: "body", + type: "fix", + description: "resolve bug", + scope: "scope", + references: [], + authors: [], + isBreaking: false, + }, + { + author: { + name: "Alice Johnson", + email: "alice@johnson.com", + }, + message: "chore: update dependencies", + shortHash: "9012", + body: "body", + type: "chore", + description: "update dependencies", + scope: "scope", + references: [], + authors: [], + isBreaking: false, + }, + { + author: { + name: "Bob Williams", + email: "bob@williams.com", + }, + message: "docs: update documentation", + shortHash: "3456", + body: "body", + type: "docs", + description: "update documentation", + scope: "scope", + references: [], + authors: [], + isBreaking: false, + }, +]; From 8a23bc85bc30cc1e55feb69af4c34e125abd9c4e Mon Sep 17 00:00:00 2001 From: Klein Petr Date: Sun, 17 Mar 2024 20:13:18 +0100 Subject: [PATCH 2/5] refactor: remove test file snapshot --- test/__snapshots__/contributors.test.ts.snap | 22 -------------------- 1 file changed, 22 deletions(-) delete mode 100644 test/__snapshots__/contributors.test.ts.snap diff --git a/test/__snapshots__/contributors.test.ts.snap b/test/__snapshots__/contributors.test.ts.snap deleted file mode 100644 index 6e75856..0000000 --- a/test/__snapshots__/contributors.test.ts.snap +++ /dev/null @@ -1,22 +0,0 @@ -// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html - -exports[`contributors > should skip authors 1`] = ` -"## v1.0.0 - - -### 🚀 Enhancements - -- **scope:** Add feature - -### 🩹 Fixes - -- **scope:** Resolve bug - -### 📖 Documentation - -- **scope:** Update documentation - -### 🏡 Chore - -- **scope:** Update dependencies" -`; From 2876b51df2e95f7d5a018229d0b6a6dc676a4db7 Mon Sep 17 00:00:00 2001 From: Klein Petr Date: Wed, 13 Nov 2024 12:46:13 +0000 Subject: [PATCH 3/5] Update README.md Co-authored-by: Philipp Kief --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index be24d03..a54a393 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,7 @@ npx changelogen@latest [...args] [--dir ] - `--dir`: Path to git repository. When not provided, **current working directory** will be used as as default. - `--clean`: Determine if the working directory is clean and if it is not clean, exit. - `--output`: Changelog file name to create or update. Defaults to `CHANGELOG.md` and resolved relative to dir. Use `--no-output` to write to console only. -- `skipAuthors`: Skip contributors section in changelog. +- `--skipAuthors`: Skip contributors section in changelog. - `--bump`: Determine semver change and update version in `package.json`. - `--release`. Bumps version in `package.json` and creates commit and git tags using local `git`. You can disable commit using `--no-commit` and tag using `--no-tag`. You can enable the automatic push of the new tag and release commit to your git repository by adding `--push`. - `--publish`. Publishes package as a new version on `npm`. You will need to set authorisation tokens separately via `.npmrc` or environment variables. From 40531d98eae442c9b6d46a21d537a09c4ee55064 Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Wed, 13 Nov 2024 12:46:46 +0000 Subject: [PATCH 4/5] chore: apply automated lint fixes --- src/markdown.ts | 2 +- test/contributors.test.ts | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/markdown.ts b/src/markdown.ts index 912312c..b0f7bf0 100644 --- a/src/markdown.ts +++ b/src/markdown.ts @@ -102,7 +102,7 @@ export async function generateMarkDown( }) ); } - + return convert(markdown.join("\n").trim(), true); } diff --git a/test/contributors.test.ts b/test/contributors.test.ts index 95e5823..782f84e 100644 --- a/test/contributors.test.ts +++ b/test/contributors.test.ts @@ -7,7 +7,7 @@ describe("contributors", () => { const config = await loadChangelogConfig(process.cwd(), { newVersion: "1.0.0", }); - const contents = await generateMarkDown(testCommits, config) + const contents = await generateMarkDown(testCommits, config); expect(contents).toMatchInlineSnapshot(` "## v1.0.0 @@ -35,15 +35,15 @@ describe("contributors", () => { - Jane Smith - Alice Johnson - Bob Williams " - `) - }) - + `); + }); + test("should skip authors", async () => { const config = await loadChangelogConfig(process.cwd(), { newVersion: "1.0.0", skipAuthors: true, }); - const contents = await generateMarkDown(testCommits, config) + const contents = await generateMarkDown(testCommits, config); expect(contents).toMatchInlineSnapshot(` "## v1.0.0 @@ -64,6 +64,6 @@ describe("contributors", () => { ### 🏡 Chore - **scope:** Update dependencies" - `) - }) + `); + }); }); From 8a6ec21ebf1621830d6f832d4005d95005d4036d Mon Sep 17 00:00:00 2001 From: Klein Petr Date: Wed, 13 Nov 2024 13:52:40 +0100 Subject: [PATCH 5/5] test: fix contributors test --- test/contributors.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/contributors.test.ts b/test/contributors.test.ts index 782f84e..2232674 100644 --- a/test/contributors.test.ts +++ b/test/contributors.test.ts @@ -31,7 +31,7 @@ describe("contributors", () => { ### ❤️ Contributors - - John Doe ([@brainsucker](http://github.com/brainsucker)) + - John Doe ([@brainsucker](https://github.com/brainsucker)) - Jane Smith - Alice Johnson - Bob Williams "