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

Add --no-git-commit option to changelog command #2258

Merged
Merged
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
8 changes: 8 additions & 0 deletions packages/cli/src/parse-args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,13 @@ const dryRun: AutoOption = {
group: "main",
};

const noGitCommit: AutoOption = {
name: "no-git-commit",
type: Boolean,
description: "Do not commit changes",
group: "main",
};

const url: AutoOption = {
name: "url",
type: String,
Expand Down Expand Up @@ -460,6 +467,7 @@ export const commands: AutoCommand[] = [
changelogCommitMessage,
baseBranch,
quiet,
noGitCommit,
],
examples: [
{
Expand Down
23 changes: 22 additions & 1 deletion packages/core/src/__tests__/auto.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -862,6 +862,23 @@ describe("Auto", () => {
expect(addToChangelog).not.toHaveBeenCalled();
});

test("should not commit on noGitCommit", async () => {
const auto = new Auto(defaults);

auto.logger = dummyLog();
await auto.loadConfig();

const addToChangelog = jest.fn();
auto.release!.addToChangelog = addToChangelog;
const beforeCommitChangelog = jest.fn();
auto.hooks.beforeCommitChangelog.tap("test", beforeCommitChangelog);
jest.spyOn(auto.release!, "generateReleaseNotes").mockImplementation();

await auto.changelog({ from: "v1.0.0", noGitCommit: true });
expect(addToChangelog).toHaveBeenCalled();
expect(beforeCommitChangelog).not.toHaveBeenCalled();
});

test("should be able to override title", async () => {
const auto = new Auto(defaults);

Expand Down Expand Up @@ -1512,13 +1529,17 @@ describe("Auto", () => {
} as any);
jest.spyOn(auto.release!, "getCommitsInRelease").mockImplementation();
jest.spyOn(auto.release!, "generateReleaseNotes").mockImplementation();
jest.spyOn(auto.release!, "addToChangelog").mockImplementation();
const addToChangelog = jest
.spyOn(auto.release!, "addToChangelog")
.mockImplementation();
const beforeCommitChangelog = jest.fn();
auto.hooks.beforeCommitChangelog.tap("test", beforeCommitChangelog);
const afterChangelog = jest.fn();
auto.hooks.afterChangelog.tap("test", afterChangelog);

await auto.shipit({ noChangelog: true });

expect(addToChangelog).not.toHaveBeenCalled();
expect(beforeCommitChangelog).not.toHaveBeenCalled();
expect(afterChangelog).toHaveBeenCalled();
});
Expand Down
10 changes: 8 additions & 2 deletions packages/core/src/auto-args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ export interface DryRunOption {
dryRun?: boolean;
}

export interface NoGitCommit {
/** Do not commit the changes */
noGitCommit?: boolean;
}

interface ChangelogTitle {
/** Override the title use in the addition to the CHANGELOG.md. */
title?: string;
Expand All @@ -70,13 +75,14 @@ export type IChangelogOptions = BaseBranch &
QuietOption &
DryRunOption &
NoVersionPrefix &
NoGitCommit &
Partial<AuthorInformation> & {
/** Commit to start calculating the changelog from */
from?: string;
/** Commit to start calculating the changelog to */
to?: string;
/** Don't commit the changelog */
noCommit?: boolean;
/** Do not make any changes to changelog file */
noChanges?: boolean;
};

export type IReleaseOptions = BaseBranch &
Expand Down
20 changes: 14 additions & 6 deletions packages/core/src/auto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1732,7 +1732,7 @@ export default class Auto {
await this.makeChangelog({
...options,
quiet: undefined,
noCommit: options.noChangelog,
noChanges: options.noChangelog,
});

if (!options.dryRun) {
Expand Down Expand Up @@ -1862,7 +1862,8 @@ export default class Auto {
to,
title,
message = "Update CHANGELOG.md [skip ci]",
noCommit,
noGitCommit,
noChanges,
} = options;

if (!this.release || !this.git) {
Expand Down Expand Up @@ -1908,16 +1909,23 @@ export default class Auto {
currentVersion,
};

if (!noCommit) {
if (!noChanges) {
await this.release.addToChangelog(
releaseNotes,
lastRelease,
currentVersion
);

await this.hooks.beforeCommitChangelog.promise(context);
await execPromise("git", ["commit", "-m", `"${message}"`, "--no-verify"]);
this.logger.verbose.info("Committed new changelog.");
if (!noGitCommit) {
await this.hooks.beforeCommitChangelog.promise(context);
await execPromise("git", [
"commit",
"-m",
`"${message}"`,
"--no-verify",
]);
this.logger.verbose.info("Committed new changelog.");
}
}

await this.hooks.afterChangelog.promise(context);
Expand Down
6 changes: 4 additions & 2 deletions packages/core/src/release.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,10 +263,12 @@ export default class Release {
: `v${version}`;
});

this.logger.verbose.info("Adding new changes to changelog.");
const fileName = "CHANGELOG.md";

this.logger.verbose.info(`Adding new changes to ${fileName}.`);
const title = await this.hooks.createChangelogTitle.promise();

await this.updateChangelogFile(title || "", releaseNotes, "CHANGELOG.md");
await this.updateChangelogFile(title || "", releaseNotes, fileName);
}

/**
Expand Down