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: add baseBranch option #373

Open
wants to merge 3 commits 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/unlucky-lies-brush.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@changesets/action": minor
---

add option 'baseBranch'
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ This action for [Changesets](https://github.com/atlassian/changesets) creates a
- setupGitUser - Sets up the git user for commits as `"github-actions[bot]"`. Default to `true`
- createGithubReleases - A boolean value to indicate whether to create Github releases after `publish` or not. Default to `true`
- cwd - Changes node's `process.cwd()` if the project is not located on the root. Default to `process.cwd()`
- baseBranch - The branch to create the pull request against. Default to the branch the action is running on.

### Outputs

Expand Down
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ inputs:
branch:
description: Sets the branch in which the action will run. Default to `github.ref_name` if not provided
required: false
baseBranch:
description: Sets the base branch for the pull request. Default to the branch the action runs on if not provided
required: false
outputs:
published:
description: A boolean value to indicate whether a publishing is happened or not
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ const getOptionalInput = (name: string) => core.getInput(name) || undefined;
commitMessage: getOptionalInput("commit"),
hasPublishScript,
branch: getOptionalInput("branch"),
baseBranch: getOptionalInput("baseBranch"),
});

core.setOutput("pullRequestNumber", String(pullRequestNumber));
Expand Down
5 changes: 4 additions & 1 deletion src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ type VersionOptions = {
hasPublishScript?: boolean;
prBodyMaxCharacters?: number;
branch?: string;
baseBranch?: string;
};

type RunVersionResult = {
Expand All @@ -315,11 +316,13 @@ export async function runVersion({
hasPublishScript = false,
prBodyMaxCharacters = MAX_CHARACTERS_PER_MESSAGE,
branch,
baseBranch,
}: VersionOptions): Promise<RunVersionResult> {
const octokit = setupOctokit(githubToken);

let repo = `${github.context.repo.owner}/${github.context.repo.repo}`;
branch = branch ?? github.context.ref.replace("refs/heads/", "");
baseBranch ??= branch;
let versionBranch = `changeset-release/${branch}`;

let { preState } = await readChangesetState(cwd);
Expand Down Expand Up @@ -396,7 +399,7 @@ export async function runVersion({
if (existingPullRequests.data.length === 0) {
core.info("creating pull request");
const { data: newPullRequest } = await octokit.rest.pulls.create({
base: branch,
base: baseBranch,
head: versionBranch,
title: finalPrTitle,
body: prBody,
Expand Down