A GitHub action to check that a PR's target branch is correct, commenting and/or changing it if required
Please note using pull_request_target
can be dangerous, read GitHub's security article here before using examples with it
name: Make sure new PRs are sent to development
on:
pull_request_target:
types: [opened, edited]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: Vankka/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
target: main
exclude: development # Don't prevent going from development -> main
change-to: development
comment: |
Your PR was set to `main`, PRs should be sent to `development`
The base branch of this PR has been automatically changed to `development`, please check that there are no merge conflicts
When change-to
and comment
are not used, pull_request_target and the GITHUB_TOKEN are not required. The Action will just fail (instead of changing the base branch or commenting) when the target branch is wrong.
name: Make sure new PRs are sent to development
on:
pull_request:
types: [opened, edited]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: Vankka/[email protected]
with:
target: main
exclude: development # Don't prevent going from development -> main
The base branch this action will check for, this also accepts a Regular Expression (pre- and suffixed with /), example values:
# Only matches the development branch
development
# Match all branches matching the pattern: feature-\w+
/feature-\\w+/
Head (or compare) branch(es) that are subject to checking, can be provided with a branch name, organization/owner name:branch name
or a Regular Expression matching the latter, example values:
# Match any branch called development
development
# Only match GitHub's development branch
GitHub:development
# Match PRs from all of GitHub's branches
/GitHub:.*/
Multiple values can be provided with a string of values separated by spaces, example:
include: "main development v1"
Head (or compare) branch(es) that will not be checked, can be provided with a branch name, organization/owner name:branch name
or a Regular Expression matching the latter, example values:
# Match any branch called development
development
# Only match GitHub's development branch
GitHub:development
# Match PRs from all of GitHub's branches
/GitHub:.*/
Multiple values can be provided with a string of values separated by spaces, example:
exclude: "main development v1"
What the PRs base branch should be changed to if the base branched matches the given criteria.
Requires using the pull_request_target
event and including the GITHUB_TOKEN
environment variable
The comment to post if the base branch matches the given criteria.
Requires using the pull_request_target
event and including the GITHUB_TOKEN
environment variable