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: formatPrettierWithChangesets option #397

Open
wants to merge 1 commit 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/grumpy-hairs-rhyme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@changesets/action": minor
---

added `formatChangesetsWithPrettier` option
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ inputs:
branch:
description: Sets the branch in which the action will run. Default to `github.ref_name` if not provided
required: false
formatChangesetsWithPrettier:
description: Set false to opt-out of prettier formatting for changelogs
default: true
required: false
outputs:
published:
description: A boolean value to indicate whether a publishing is happened or not
Expand Down
33 changes: 33 additions & 0 deletions src/__snapshots__/run.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,38 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`version can opt out of prettier 1`] = `
[
{
"base": "some-branch",
"body": "This PR was opened by the [Changesets release](https://github.com/changesets/action) GitHub action. When you're ready to do a release, you can merge this and publish to npm yourself or [setup this action to publish automatically](https://github.com/changesets/action#with-publishing). If you're not ready to do a release yet, that's fine, whenever you add more changesets to some-branch, this PR will be updated.


# Releases
## [email protected]

### Minor Changes

- This is a summary

\`\`\`html
<style>custom-element::part(thing) {color:blue}</style>
\`\`\`

## [email protected]

### Patch Changes

- Updated dependencies
- [email protected]
",
"head": "changeset-release/some-branch",
"owner": "changesets",
"repo": "action",
"title": "Version Packages",
},
]
`;

exports[`version creates simple PR 1`] = `
[
{
Expand Down
6 changes: 1 addition & 5 deletions src/gitUtils.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import { exec, getExecOutput } from "@actions/exec";

export const setupUser = async () => {
await exec("git", [
"config",
"user.name",
`"github-actions[bot]"`,
]);
await exec("git", ["config", "user.name", `"github-actions[bot]"`]);
await exec("git", [
"config",
"user.email",
Expand Down
3 changes: 3 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ const getOptionalInput = (name: string) => core.getInput(name) || undefined;
prTitle: getOptionalInput("title"),
commitMessage: getOptionalInput("commit"),
hasPublishScript,
formatChangesetsWithPrettier: core.getBooleanInput(
"formatChangesetsWithPrettier"
),
branch: getOptionalInput("branch"),
});

Expand Down
58 changes: 48 additions & 10 deletions src/run.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@ jest.mock("@actions/github", () => ({
},
}));
jest.mock("@actions/github/lib/utils", () => ({
GitHub: {
plugin: () => {
// function necessary to be used as constructor
return function() {
return {
rest: mockedGithubMethods,
}
}
},
GitHub: {
plugin: () => {
// function necessary to be used as constructor
return function () {
return {
rest: mockedGithubMethods,
};
};
},
getOctokitOptions: jest.fn(),
},
getOctokitOptions: jest.fn(),
}));
jest.mock("./gitUtils");

Expand Down Expand Up @@ -96,6 +96,44 @@ describe("version", () => {
expect(mockedGithubMethods.pulls.create.mock.calls[0]).toMatchSnapshot();
});

it("can opt out of prettier", async () => {
let cwd = f.copy("simple-project");
linkNodeModules(cwd);

mockedGithubMethods.pulls.list.mockImplementationOnce(() => ({ data: [] }));

mockedGithubMethods.pulls.create.mockImplementationOnce(() => ({
data: { number: 123 },
}));

const summary = `This is a summary
~~~html
<style>custom-element::part(thing) {color:blue}</style>
~~~`;

await writeChangesets(
[
{
releases: [
{
name: "simple-project-pkg-b",
type: "minor",
},
],
summary,
},
],
cwd
);

await runVersion({
githubToken: "@@GITHUB_TOKEN",
cwd,
});

expect(mockedGithubMethods.pulls.create.mock.calls[0]).toMatchSnapshot();
});

it("only includes bumped packages in the PR body", async () => {
let cwd = f.copy("simple-project");
linkNodeModules(cwd);
Expand Down
8 changes: 7 additions & 1 deletion src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ type VersionOptions = {
commitMessage?: string;
hasPublishScript?: boolean;
prBodyMaxCharacters?: number;
formatChangesetsWithPrettier?: boolean;
branch?: string;
};

Expand All @@ -314,6 +315,7 @@ export async function runVersion({
commitMessage = "Version Packages",
hasPublishScript = false,
prBodyMaxCharacters = MAX_CHARACTERS_PER_MESSAGE,
formatChangesetsWithPrettier = true,
branch,
}: VersionOptions): Promise<RunVersionResult> {
const octokit = setupOctokit(githubToken);
Expand All @@ -337,7 +339,11 @@ export async function runVersion({
let cmd = semver.lt(changesetsCliPkgJson.version, "2.0.0")
? "bump"
: "version";
await exec("node", [resolveFrom(cwd, "@changesets/cli/bin.js"), cmd], {

const args = [resolveFrom(cwd, "@changesets/cli/bin.js"), cmd];
if (formatChangesetsWithPrettier === false)
args.push("--noFormatChangesetsWithPrettier");
await exec("node", args, {
cwd,
});
}
Expand Down