diff --git a/action.yml b/action.yml index 89fe87a7..259fb5ed 100644 --- a/action.yml +++ b/action.yml @@ -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 diff --git a/src/__snapshots__/run.test.ts.snap b/src/__snapshots__/run.test.ts.snap index aa9b5d9b..398b875d 100644 --- a/src/__snapshots__/run.test.ts.snap +++ b/src/__snapshots__/run.test.ts.snap @@ -25,6 +25,7 @@ exports[`version > creates simple PR 1`] = ` - Awesome feature ", + "draft": false, "head": "changeset-release/some-branch", "owner": "changesets", "repo": "action", @@ -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", @@ -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", @@ -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", @@ -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", diff --git a/src/index.ts b/src/index.ts index 7021e49c..ff5cdbd1 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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)); diff --git a/src/run.test.ts b/src/run.test.ts index 90c9fc00..7b5b1ae6 100644 --- a/src/run.test.ts +++ b/src/run.test.ts @@ -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); diff --git a/src/run.ts b/src/run.ts index 5ddb33e3..d2244c1f 100644 --- a/src/run.ts +++ b/src/run.ts @@ -260,6 +260,7 @@ type VersionOptions = { hasPublishScript?: boolean; prBodyMaxCharacters?: number; branch?: string; + draftPullRequest?: boolean; }; type RunVersionResult = { @@ -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 { let versionBranch = `changeset-release/${branch}`; @@ -376,6 +378,7 @@ export async function runVersion({ head: versionBranch, title: finalPrTitle, body: prBody, + draft: draftPullRequest, ...github.context.repo, });