Skip to content

Commit

Permalink
feat: add noAuthors option (#183)
Browse files Browse the repository at this point in the history
Co-authored-by: Philipp Kief <[email protected]>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: Pooya Parsa <[email protected]>
  • Loading branch information
4 people authored Feb 26, 2025
1 parent 8c354da commit 46cd50c
Show file tree
Hide file tree
Showing 6 changed files with 138 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ npx changelogen@latest [...args] [--dir <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.
- `--noAuthors`: 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.
Expand Down
1 change: 1 addition & 0 deletions src/commands/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
noAuthors: args.noAuthors,
});

if (args.clean) {
Expand Down
2 changes: 2 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export interface ChangelogConfig {
tagMessage?: string;
tagBody?: string;
};
noAuthors: boolean;
excludeAuthors: string[];
hideAuthorEmail?: boolean;
}
Expand Down Expand Up @@ -73,6 +74,7 @@ const getDefaultConfig = () =>
tagBody: "v{{newVersion}}",
},
excludeAuthors: [],
noAuthors: false,
};

export async function loadChangelogConfig(
Expand Down
2 changes: 1 addition & 1 deletion src/markdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,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.noAuthors) {
markdown.push(
"",
"### " + "❤️ Contributors",
Expand Down
71 changes: 71 additions & 0 deletions test/contributors.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
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
[compare changes](https://github.com/unjs/changelogen/compare/v0.5.7...v1.0.0)
### 🚀 Enhancements
- **scope:** Add feature
### 🩹 Fixes
- **scope:** Resolve bug
### 📖 Documentation
- **scope:** Update documentation
### 🏡 Chore
- **scope:** Update dependencies
### ❤️ Contributors
- John Doe ([@brainsucker](https://github.com/brainsucker))
- Jane Smith <[email protected]>
- Alice Johnson <[email protected]>
- Bob Williams <[email protected]>"
`);
});

test("should skip authors with noAuthors config", async () => {
const config = await loadChangelogConfig(process.cwd(), {
newVersion: "1.0.0",
noAuthors: true,
});
const contents = await generateMarkDown(testCommits, config);

expect(contents).toMatchInlineSnapshot(`
"## v1.0.0
[compare changes](https://github.com/unjs/changelogen/compare/v0.5.7...v1.0.0)
### 🚀 Enhancements
- **scope:** Add feature
### 🩹 Fixes
- **scope:** Resolve bug
### 📖 Documentation
- **scope:** Update documentation
### 🏡 Chore
- **scope:** Update dependencies"
`);
});
});
62 changes: 62 additions & 0 deletions test/fixtures/commits.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
export const testCommits = [
{
author: {
name: "John Doe",
email: "[email protected]",
},
message: "feat: add feature",
shortHash: "1234",
body: "body",
type: "feat",
description: "add feature",
scope: "scope",
references: [],
authors: [],
isBreaking: false,
},
{
author: {
name: "Jane Smith",
email: "[email protected]",
},
message: "fix: resolve bug",
shortHash: "5678",
body: "body",
type: "fix",
description: "resolve bug",
scope: "scope",
references: [],
authors: [],
isBreaking: false,
},
{
author: {
name: "Alice Johnson",
email: "[email protected]",
},
message: "chore: update dependencies",
shortHash: "9012",
body: "body",
type: "chore",
description: "update dependencies",
scope: "scope",
references: [],
authors: [],
isBreaking: false,
},
{
author: {
name: "Bob Williams",
email: "[email protected]",
},
message: "docs: update documentation",
shortHash: "3456",
body: "body",
type: "docs",
description: "update documentation",
scope: "scope",
references: [],
authors: [],
isBreaking: false,
},
];

0 comments on commit 46cd50c

Please sign in to comment.