diff --git a/.changeset/early-pumas-live.md b/.changeset/early-pumas-live.md new file mode 100644 index 00000000..c2ab90bf --- /dev/null +++ b/.changeset/early-pumas-live.md @@ -0,0 +1,5 @@ +--- +"@changesets/action": minor +--- + +Add `branch` input to configure the pull request source diff --git a/action.yml b/action.yml index c9ca1b68..79f0058a 100644 --- a/action.yml +++ b/action.yml @@ -28,6 +28,9 @@ inputs: description: "A boolean value to indicate whether to create Github releases after `publish` or not" required: false default: true + branch: + description: The branch to use for when applying changesets and creating the pull requests. + required: 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 9ce562c1..2862bf1f 100644 --- a/src/__snapshots__/run.test.ts.snap +++ b/src/__snapshots__/run.test.ts.snap @@ -32,6 +32,38 @@ Array [ ] `; +exports[`version creates simple PR for a custom branch 1`] = ` +Array [ + Object { + "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 +## simple-project-pkg-a@1.1.0 + +### Minor Changes + +- Awesome feature + +### Patch Changes + +- Updated dependencies + - simple-project-pkg-b@1.1.0 + + ## simple-project-pkg-b@1.1.0 + +### Minor Changes + +- Awesome feature +", + "head": "feat/my-custom-branch", + "owner": "changesets", + "repo": "action", + "title": "Version Packages", + }, +] +`; + exports[`version doesn't include ignored package that got a dependency update in the PR body 1`] = ` Array [ Object { @@ -73,3 +105,34 @@ Array [ }, ] `; + +exports[`version updates simple PR for a custom branch 1`] = ` +Array [ + Object { + "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 +## simple-project-pkg-a@1.1.0 + +### Minor Changes + +- Awesome feature + +### Patch Changes + +- Updated dependencies + - simple-project-pkg-b@1.1.0 + + ## simple-project-pkg-b@1.1.0 + +### Minor Changes + +- Awesome feature +", + "owner": "changesets", + "pull_number": undefined, + "repo": "action", + "title": "Version Packages", + }, +] +`; diff --git a/src/index.ts b/src/index.ts index 087eccc5..f3cd9bfb 100644 --- a/src/index.ts +++ b/src/index.ts @@ -103,6 +103,7 @@ const getOptionalInput = (name: string) => core.getInput(name) || undefined; prTitle: getOptionalInput("title"), commitMessage: getOptionalInput("commit"), hasPublishScript, + branch: getOptionalInput("branch"), }); core.setOutput("pullRequestNumber", String(pullRequestNumber)); diff --git a/src/run.test.ts b/src/run.test.ts index f156402e..d9812629 100644 --- a/src/run.test.ts +++ b/src/run.test.ts @@ -25,6 +25,7 @@ let mockedGithubMethods = { }, pulls: { create: jest.fn(), + update: jest.fn(), }, repos: { createRelease: jest.fn(), @@ -85,9 +86,88 @@ describe("version", () => { cwd, }); + expect(mockedGithubMethods.pulls.update).toHaveBeenCalledTimes(0); expect(mockedGithubMethods.pulls.create.mock.calls[0]).toMatchSnapshot(); }); + it("creates simple PR for a custom branch", async () => { + let cwd = f.copy("simple-project"); + linkNodeModules(cwd); + + mockedGithubMethods.search.issuesAndPullRequests.mockImplementationOnce( + () => ({ data: { items: [] } }) + ); + + mockedGithubMethods.pulls.create.mockImplementationOnce( + () => ({ data: { number: 123 } }) + ); + + await writeChangesets( + [ + { + releases: [ + { + name: "simple-project-pkg-a", + type: "minor", + }, + { + name: "simple-project-pkg-b", + type: "minor", + }, + ], + summary: "Awesome feature", + }, + ], + cwd + ); + + await runVersion({ + githubToken: "@@GITHUB_TOKEN", + cwd, + branch: 'feat/my-custom-branch' + }); + + expect(mockedGithubMethods.pulls.update).toHaveBeenCalledTimes(0); + expect(mockedGithubMethods.pulls.create.mock.calls[0]).toMatchSnapshot(); + }); + + it("updates simple PR for a custom branch", async () => { + let cwd = f.copy("simple-project"); + linkNodeModules(cwd); + + mockedGithubMethods.search.issuesAndPullRequests.mockImplementationOnce( + () => ({ data: { items: [{}] } }) + ); + + await writeChangesets( + [ + { + releases: [ + { + name: "simple-project-pkg-a", + type: "minor", + }, + { + name: "simple-project-pkg-b", + type: "minor", + }, + ], + summary: "Awesome feature", + }, + ], + cwd + ); + + await runVersion({ + githubToken: "@@GITHUB_TOKEN", + cwd, + branch: 'feat/my-custom-branch' + }); + + expect(mockedGithubMethods.pulls.create).toHaveBeenCalledTimes(0); + expect(mockedGithubMethods.pulls.update.mock.calls[0]).toMatchSnapshot(); + }); + it("only includes bumped packages in the PR body", async () => { let cwd = f.copy("simple-project"); linkNodeModules(cwd); diff --git a/src/run.ts b/src/run.ts index 09b140ee..ef93c47b 100644 --- a/src/run.ts +++ b/src/run.ts @@ -175,6 +175,7 @@ type VersionOptions = { prTitle?: string; commitMessage?: string; hasPublishScript?: boolean; + branch?: string; }; type RunVersionResult = { @@ -188,10 +189,11 @@ export async function runVersion({ prTitle = "Version Packages", commitMessage = "Version Packages", hasPublishScript = false, + branch: inputBranch, }: VersionOptions): Promise { let repo = `${github.context.repo.owner}/${github.context.repo.repo}`; let branch = github.context.ref.replace("refs/heads/", ""); - let versionBranch = `changeset-release/${branch}`; + let versionBranch = inputBranch ? inputBranch : `changeset-release/${branch}`; let octokit = github.getOctokit(githubToken); let { preState } = await readChangesetState(cwd);