Prevent people from targeting specific branches on Github

I would like to know if there's a way of protecting specific branches from random people that wants to contribute to a project.

For example:

I've master, develop and beta branches in my project and sometimes people create pull request targeting master or even beta. What I would like is that, when they create their pull request only the develop branch can be the selected (aka "Base" on github)

like this

Is this possible ?

Upvotes: 4

Views: 116

Answers (1)

VonC
VonC

Reputation: 1324188

Similarely to the GitHub Action (workflow set on GitHub server side) "hmarr/auto-approve-action", you can write then set-up an "auti-reject action".

name: Auto approve
on: pull_request_target

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    - uses: <you>/auto-reject-action@v1
      with:
        github-token: "${{ secrets.GITHUB_TOKEN }}"

That action would automatically reject a PR done with, as a target, a branch you would not approve of.

await client.pulls.createReview({
      owner: context.repo.owner,
      repo: context.repo.repo,
      pull_number: prNumber,
      event: "REJECT",
    });
    core.info(`pull request #${prNumber} done on the wrong branch`);

Upvotes: 1

Related Questions