Skip to content
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
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ inputs:
branch:
description: Sets the branch in which the action will run. Default to `github.ref_name` if not provided
required: false
draftPullRequest:
description: "A boolean value to indicate whether the version PR should be opened as a draft. Default to `false`"
required: false
default: false
outputs:
published:
description: A boolean value to indicate whether a publishing is happened or not
Expand Down
5 changes: 5 additions & 0 deletions src/__snapshots__/run.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ exports[`version > creates simple PR 1`] = `

- Awesome feature
",
"draft": false,
"head": "changeset-release/some-branch",
"owner": "changesets",
"repo": "action",
Expand All @@ -43,6 +44,7 @@ exports[`version > does not include any release information if a message with si
# Releases

> All release information have been omitted from this message, as the content exceeds the size limit.",
"draft": false,
"head": "changeset-release/some-branch",
"owner": "changesets",
"repo": "action",
Expand All @@ -65,6 +67,7 @@ exports[`version > does not include changelog entries if full message exceeds si
## simple-project-pkg-a@1.1.0

",
"draft": false,
"head": "changeset-release/some-branch",
"owner": "changesets",
"repo": "action",
Expand All @@ -87,6 +90,7 @@ exports[`version > doesn't include ignored package that got a dependency update

- Awesome feature
",
"draft": false,
"head": "changeset-release/some-branch",
"owner": "changesets",
"repo": "action",
Expand All @@ -109,6 +113,7 @@ exports[`version > only includes bumped packages in the PR body 1`] = `

- Awesome feature
",
"draft": false,
"head": "changeset-release/some-branch",
"owner": "changesets",
"repo": "action",
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ const getOptionalInput = (name: string) => core.getInput(name) || undefined;
commitMessage: getOptionalInput("commit"),
hasPublishScript,
branch: getOptionalInput("branch"),
draftPullRequest: core.getBooleanInput("draftPullRequest"),
});

core.setOutput("pullRequestNumber", String(pullRequestNumber));
Expand Down
73 changes: 73 additions & 0 deletions src/run.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,79 @@ describe("version", () => {
expect(mockedGithubMethods.pulls.create.mock.calls[0]).toMatchSnapshot();
});

it("creates a draft PR when draftPullRequest is true", async () => {
let cwd = f.copy("simple-project");
await linkNodeModules(cwd);

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

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

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

await runVersion({
octokit: setupOctokit("@@GITHUB_TOKEN"),
githubToken: "@@GITHUB_TOKEN",
git: new Git({ cwd }),
cwd,
draftPullRequest: true,
});

expect(mockedGithubMethods.pulls.create.mock.calls[0][0].draft).toBe(true);
});

it("creates a non-draft PR by default", async () => {
let cwd = f.copy("simple-project");
await linkNodeModules(cwd);

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

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

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

await runVersion({
octokit: setupOctokit("@@GITHUB_TOKEN"),
githubToken: "@@GITHUB_TOKEN",
git: new Git({ cwd }),
cwd,
});

expect(mockedGithubMethods.pulls.create.mock.calls[0][0].draft).toBe(
false
);
});

it("does not include changelog entries if full message exceeds size limit", async () => {
let cwd = f.copy("simple-project");
await linkNodeModules(cwd);
Expand Down
3 changes: 3 additions & 0 deletions src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ type VersionOptions = {
hasPublishScript?: boolean;
prBodyMaxCharacters?: number;
branch?: string;
draftPullRequest?: boolean;
};

type RunVersionResult = {
Expand All @@ -277,6 +278,7 @@ export async function runVersion({
hasPublishScript = false,
prBodyMaxCharacters = MAX_CHARACTERS_PER_MESSAGE,
branch = github.context.ref.replace("refs/heads/", ""),
draftPullRequest = false,
}: VersionOptions): Promise<RunVersionResult> {
let versionBranch = `changeset-release/${branch}`;

Expand Down Expand Up @@ -376,6 +378,7 @@ export async function runVersion({
head: versionBranch,
title: finalPrTitle,
body: prBody,
draft: draftPullRequest,
...github.context.repo,
});

Expand Down