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
5 changes: 5 additions & 0 deletions .changeset/early-pumas-live.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@changesets/action": minor
---

Add `branch` input to configure the pull request source
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
63 changes: 63 additions & 0 deletions src/__snapshots__/run.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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",
},
]
`;
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
80 changes: 80 additions & 0 deletions src/run.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ let mockedGithubMethods = {
},
pulls: {
create: jest.fn(),
update: jest.fn(),
},
repos: {
createRelease: jest.fn(),
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 3 additions & 1 deletion src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ type VersionOptions = {
prTitle?: string;
commitMessage?: string;
hasPublishScript?: boolean;
branch?: string;
};

type RunVersionResult = {
Expand All @@ -188,10 +189,11 @@ export async function runVersion({
prTitle = "Version Packages",
commitMessage = "Version Packages",
hasPublishScript = false,
branch: inputBranch,
}: VersionOptions): Promise<RunVersionResult> {
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);

Expand Down