Skip to content

Commit 8c2a439

Browse files
committed
Add an override for the base branch
1 parent c5ff844 commit 8c2a439

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ These variables are *all optional*. If not set, sensible default values will be
5151
| `PULL_REQUEST_TEAM_REVIEWERS` | A comma separated list of GitHub teams to request a review from. | none |
5252
| `PULL_REQUEST_MILESTONE` | The number of the milestone to associate this pull request with. | none |
5353
| `PULL_REQUEST_BRANCH` | The branch name. See **Branch naming** below for details. | `create-pull-request/patch` |
54+
| `PULL_REQUEST_BASE` | Overrides the base branch. **Use with caution!** | Defaults to the currently checked out branch. |
5455
| `BRANCH_SUFFIX` | The branch suffix type. Valid values are `short-commit-hash`, `timestamp`, `random` and `none`. See **Branch naming** below for details. | `short-commit-hash` |
5556

5657
**Output environment variables**

create-pull-request.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,12 +184,17 @@ def process_event(event_name, event_data, repo, branch, base, remote_exists):
184184
# Set the base branch
185185
github_ref = os.environ['GITHUB_REF']
186186
if github_ref.startswith('refs/pull/'):
187+
# Switch to the merging branch instead of the merge commit
187188
base = os.environ['GITHUB_HEAD_REF']
188-
# Reset to the merging branch instead of the merge commit
189-
repo.git.checkout(base)
190189
else:
191190
base = github_ref[11:]
192191

192+
# Optional base override
193+
base = os.getenv('PULL_REQUEST_BASE', base)
194+
195+
# Checkout the base branch
196+
repo.git.checkout(base)
197+
193198
# Skip if the current branch is a PR branch created by this action
194199
if base.startswith(branch):
195200
print("Branch '%s' was created by this action. Skipping." % base)

0 commit comments

Comments
 (0)