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

feat: add skipAuthors (boolean) option #183

Open
wants to merge 2 commits into
base: main
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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.
- `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.
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,
skipAuthors: args.skipAuthors,
});

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 @@ -27,6 +27,7 @@ export interface ChangelogConfig {
tagBody?: string;
};
excludeAuthors: string[];
skipAuthors: boolean;
}

export type ResolvedChangelogConfig = Omit<ChangelogConfig, "repo"> & {
Expand Down Expand Up @@ -72,6 +73,7 @@ const getDefaultConfig = () =>
tagBody: "v{{newVersion}}",
},
excludeAuthors: [],
skipAuthors: false,
};

export async function loadChangelogConfig(
Expand Down
4 changes: 2 additions & 2 deletions src/markdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -102,7 +102,7 @@ export async function generateMarkDown(
})
);
}

return convert(markdown.join("\n").trim(), true);
}

Expand Down
69 changes: 69 additions & 0 deletions test/contributors.test.ts
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>
- Alice Johnson <[email protected]>
- Bob Williams <[email protected]>"
`)
})

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"
`)
})
});
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,
},
];