Skip to content

Commit 46cd50c

Browse files
kleinpetrPKiefautofix-ci[bot]pi0
authored
feat: add noAuthors option (#183)
Co-authored-by: Philipp Kief <philipp.kief@gmx.de> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Pooya Parsa <pooya@pi0.io>
1 parent 8c354da commit 46cd50c

File tree

6 files changed

+138
-1
lines changed

6 files changed

+138
-1
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ npx changelogen@latest [...args] [--dir <dir>]
4040
- `--dir`: Path to git repository. When not provided, **current working directory** will be used as as default.
4141
- `--clean`: Determine if the working directory is clean and if it is not clean, exit.
4242
- `--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.
43+
- `--noAuthors`: Skip contributors section in changelog.
4344
- `--bump`: Determine semver change and update version in `package.json`.
4445
- `--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`.
4546
- `--publish`. Publishes package as a new version on `npm`. You will need to set authorisation tokens separately via `.npmrc` or environment variables.

src/commands/default.ts

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export default async function defaultMain(args: Argv) {
2525
to: args.to,
2626
output: args.output,
2727
newVersion: typeof args.r === "string" ? args.r : undefined,
28+
noAuthors: args.noAuthors,
2829
});
2930

3031
if (args.clean) {

src/config.ts

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export interface ChangelogConfig {
2626
tagMessage?: string;
2727
tagBody?: string;
2828
};
29+
noAuthors: boolean;
2930
excludeAuthors: string[];
3031
hideAuthorEmail?: boolean;
3132
}
@@ -73,6 +74,7 @@ const getDefaultConfig = () =>
7374
tagBody: "v{{newVersion}}",
7475
},
7576
excludeAuthors: [],
77+
noAuthors: false,
7678
};
7779

7880
export async function loadChangelogConfig(

src/markdown.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export async function generateMarkDown(
8787

8888
const authors = [..._authors.entries()].map((e) => ({ name: e[0], ...e[1] }));
8989

90-
if (authors.length > 0) {
90+
if (authors.length > 0 && !config.noAuthors) {
9191
markdown.push(
9292
"",
9393
"### " + "❤️ Contributors",

test/contributors.test.ts

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import { describe, expect, test } from "vitest";
2+
import { loadChangelogConfig, generateMarkDown } from "../src";
3+
import { testCommits } from "./fixtures/commits";
4+
5+
describe("contributors", () => {
6+
test("should include authors", async () => {
7+
const config = await loadChangelogConfig(process.cwd(), {
8+
newVersion: "1.0.0",
9+
});
10+
const contents = await generateMarkDown(testCommits, config);
11+
12+
expect(contents).toMatchInlineSnapshot(`
13+
"## v1.0.0
14+
15+
[compare changes](https://github.com/unjs/changelogen/compare/v0.5.7...v1.0.0)
16+
17+
### 🚀 Enhancements
18+
19+
- **scope:** Add feature
20+
21+
### 🩹 Fixes
22+
23+
- **scope:** Resolve bug
24+
25+
### 📖 Documentation
26+
27+
- **scope:** Update documentation
28+
29+
### 🏡 Chore
30+
31+
- **scope:** Update dependencies
32+
33+
### ❤️ Contributors
34+
35+
- John Doe ([@brainsucker](https://github.com/brainsucker))
36+
- Jane Smith <jane@smith.com>
37+
- Alice Johnson <alice@johnson.com>
38+
- Bob Williams <bob@williams.com>"
39+
`);
40+
});
41+
42+
test("should skip authors with noAuthors config", async () => {
43+
const config = await loadChangelogConfig(process.cwd(), {
44+
newVersion: "1.0.0",
45+
noAuthors: true,
46+
});
47+
const contents = await generateMarkDown(testCommits, config);
48+
49+
expect(contents).toMatchInlineSnapshot(`
50+
"## v1.0.0
51+
52+
[compare changes](https://github.com/unjs/changelogen/compare/v0.5.7...v1.0.0)
53+
54+
### 🚀 Enhancements
55+
56+
- **scope:** Add feature
57+
58+
### 🩹 Fixes
59+
60+
- **scope:** Resolve bug
61+
62+
### 📖 Documentation
63+
64+
- **scope:** Update documentation
65+
66+
### 🏡 Chore
67+
68+
- **scope:** Update dependencies"
69+
`);
70+
});
71+
});

test/fixtures/commits.ts

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
export const testCommits = [
2+
{
3+
author: {
4+
name: "John Doe",
5+
email: "john@doe.com",
6+
},
7+
message: "feat: add feature",
8+
shortHash: "1234",
9+
body: "body",
10+
type: "feat",
11+
description: "add feature",
12+
scope: "scope",
13+
references: [],
14+
authors: [],
15+
isBreaking: false,
16+
},
17+
{
18+
author: {
19+
name: "Jane Smith",
20+
email: "jane@smith.com",
21+
},
22+
message: "fix: resolve bug",
23+
shortHash: "5678",
24+
body: "body",
25+
type: "fix",
26+
description: "resolve bug",
27+
scope: "scope",
28+
references: [],
29+
authors: [],
30+
isBreaking: false,
31+
},
32+
{
33+
author: {
34+
name: "Alice Johnson",
35+
email: "alice@johnson.com",
36+
},
37+
message: "chore: update dependencies",
38+
shortHash: "9012",
39+
body: "body",
40+
type: "chore",
41+
description: "update dependencies",
42+
scope: "scope",
43+
references: [],
44+
authors: [],
45+
isBreaking: false,
46+
},
47+
{
48+
author: {
49+
name: "Bob Williams",
50+
email: "bob@williams.com",
51+
},
52+
message: "docs: update documentation",
53+
shortHash: "3456",
54+
body: "body",
55+
type: "docs",
56+
description: "update documentation",
57+
scope: "scope",
58+
references: [],
59+
authors: [],
60+
isBreaking: false,
61+
},
62+
];

0 commit comments

Comments
 (0)