From 8c2a43987b627a8803600760abdca6053e3a927a Mon Sep 17 00:00:00 2001 From: Peter Evans Date: Mon, 21 Oct 2019 20:17:31 +0900 Subject: [PATCH] Add an override for the base branch --- README.md | 1 + create-pull-request.py | 9 +++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 2690b6f..9ec8de7 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,7 @@ These variables are *all optional*. If not set, sensible default values will be | `PULL_REQUEST_TEAM_REVIEWERS` | A comma separated list of GitHub teams to request a review from. | none | | `PULL_REQUEST_MILESTONE` | The number of the milestone to associate this pull request with. | none | | `PULL_REQUEST_BRANCH` | The branch name. See **Branch naming** below for details. | `create-pull-request/patch` | +| `PULL_REQUEST_BASE` | Overrides the base branch. **Use with caution!** | Defaults to the currently checked out branch. | | `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` | **Output environment variables** diff --git a/create-pull-request.py b/create-pull-request.py index 5035fac..8d68c27 100755 --- a/create-pull-request.py +++ b/create-pull-request.py @@ -184,12 +184,17 @@ if skip_ignore_event or not ignore_event(event_name, event_data): # Set the base branch github_ref = os.environ['GITHUB_REF'] if github_ref.startswith('refs/pull/'): + # Switch to the merging branch instead of the merge commit base = os.environ['GITHUB_HEAD_REF'] - # Reset to the merging branch instead of the merge commit - repo.git.checkout(base) else: base = github_ref[11:] + # Optional base override + base = os.getenv('PULL_REQUEST_BASE', base) + + # Checkout the base branch + repo.git.checkout(base) + # Skip if the current branch is a PR branch created by this action if base.startswith(branch): print("Branch '%s' was created by this action. Skipping." % base)