a GitHub bot that switches the base branch of pull requests to the preferred branch
APACHE-2.0 License
A GitHub App built with Probot that automatically updates the base ref of a pull request if it has been opened against a non-preferred branch.
In projects where the default branch is not master, pull requests are often opened against a wrong branch. Typically, maintainers of the project need to reach out to the authors and ask them to change the base branch as most bigger projects have automated tests configured against the default branch.
The intent of this GitHub app is to support maintainers by automatically changing the base branch of pull requests to the default branch if applicable. The app listens to a set of webhooks:
pull_request.opened
,pull_request.reopened
,pull_request.edited
,pull_request.labeled
,pull_request.unlabeled
,which triggers
.github/branch-switcher.yml
file in the root of the intended repositories whereThe following properties are currently supported:
preferredBranch
(string) - name of the preferred branch against which theswitchComment
(string) - content of the message indicating that the base{{author}}
can be used as a placeholder{{preferredBranch}}
analogously.exclude
(Array) - list of all branches and labels that should be ignored.branch
(string) - name of the branch that should be ignored.label
(string) - name of the label that should be ignored.Example .github/branch-switcher.yml
:
exclude:
- branch: do-nothing
- branch: dont-touch-*
- label: ignore-me
switchComment: >
Hey @{{author}}, the base branch of your pull request has been changed
to {{preferredBranch}}. Have a nice day! :wave:
Above config does not touch the base branch if there is a label ignore-me
attached
on the pull request and it also does not switch if the base branch is either called
do-nothing
or every branch matching the wildcard dont-touch-*
.
.github/branch-switcher.yml
git clone [email protected]:s4heid/branch-switcher.git
.env
and set the right environment variables as described in the official probot docs
# Install dependencies
npm install
# Run typescript and run the bot
npm run build && npm start
If you have suggestions for how branch-switcher could be improved, or want to report a bug, open an issue! We'd love all and any contributions.
For more, check out the Contributing Guide.