Reject Pull Request creation request if PR message body validation fails

727 Views Asked by At

Is there a way we can reject the Pull Request creation if certain conditions fail ? I am developing a GitHub App in nodejs and probot and would like to reject the pull request creation when the developer clicks on the "Create pull request" button if the validation (like checking for the presence of some pattern in the body of pull request) fails for Pull Request body.

So, fundamentally the Pull Request should not be created in the first place(and user should be taken back to the PR creation page), if certain validation fails.

i.e. be on the same pull request creation page, if validation of pull request body(or just any other logic) fails.

1

There are 1 best solutions below

2
On

So, fundamentally the Pull Request should not be created in the first place

This is not possible. The creation of a pull request is an atomic operation, it doesn't pause for checks like for example a pre-receive hook in Git, where you can analysis the payload of a commit and then based on a response it wither fails or gets added to the repo.

The best option you have here, is to automatically close the pull request with a comment providing instructions and the reason why it failed. I understand this can cause a lot of "empty" PRs but this is your closest solution.

The other thing you could do which is only possible in recent days, is to leave the pull request open and convert it to draft if your logic fails. Only when the user corrects the pull request to your standard you would then toggle it to non-draft: https://developer.github.com/v3/pulls/#update-a-pull-request. Of course in this situation you have to monitor the events that change the pull request.