Skip to content

Commit

Permalink
Add an override for the base branch
Browse files Browse the repository at this point in the history
  • Loading branch information
peter-evans committed Oct 21, 2019
1 parent c5ff844 commit 8c2a439
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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**
Expand Down
9 changes: 7 additions & 2 deletions create-pull-request.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,12 +184,17 @@ def process_event(event_name, event_data, repo, branch, base, remote_exists):
# 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)
Expand Down

0 comments on commit 8c2a439

Please sign in to comment.