Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GitHub - block merge PR by committers

I am looking for a way by GitHub setting or CircleCI settings preventing the person that is involved in PR (create PR or make a commit) to be able to merge PR (or even approve it). So far I have the protection of a branch that requires approvals but post-approval I as PR creator and committer I still able to merge.

like image 336
bensiu Avatar asked Jun 26 '20 19:06

bensiu


People also ask

How do you restrict who can merge pull request GitHub?

You can require pull requests to pass a set of checks before they can be merged. For example, you can block pull requests that don't pass status checks or require that pull requests have a specific number of approving reviews before they can be merged.

How do you restrict who can approve Pull Requests?

Under Access, click Moderation options. Under Moderation options, click Code review limits. Select or deselect Limit to users explicitly granted read or higher access.


1 Answers

You need to be able to

prevent the person that is involved in PR (create PR or make a commit) to be able to merge PR (or even approve it)

A contributor who has created a PR cannot approve or request changes by default in GitHub, so that is already taken care of.

Since a Pull Request is a GitHub feature, a PR merge can currently only be blocked by 2 ways

  • Using GitHub's settings
  • Using pre-receive hooks (only for GitHub Enterprise)

Using GitHub's settings, you can only block merging by requiring either pull request reviews, status checks to pass, signed commits or linear history as shown under the branch protection settings.

enter image description here

or by allowing merge commits, squash merging or rebase merging as shown in the Merge button section under repo settings

enter image description here

If you are on GitHub Enterprise, you can use a pre-receive hook (documentation) like below and ensure that self merging PRs are blocked (This eg is here)

if [[ "$GITHUB_VIA" = *"merge"* ]] && [[ "$GITHUB_PULL_REQUEST_AUTHOR_LOGIN" = "$GITHUB_USER_LOGIN" ]]; then
    echo "Blocking merging of your own pull request."
    exit 1
fi

exit 0

Apart from the above, there is no other way currently to block self merging PRs on GitHub. And using CircleCI or any other CI workflow can only block merging for everybody(if you opt for the requirement of status checks on GitHub) or nobody, as it can't control the PR merge button.

like image 81
Madhu Bhat Avatar answered Sep 20 '22 05:09

Madhu Bhat