Search code examples
githubpull-requestgithub-issues

How do I require a linked issue in a github pull request before allowing the PR to be merged/closed


Is there a way to force an issue to be linked to a PR before allowing the user to merge/close the PR? I was able to set up all of the other checks in the branch protection rule, but I cannot find a way to check that there is at least 1 linked issue.

enter image description here


Solution

  • There is no intrinsic way to require this. However, you can use a CI check, such as a GitHub Action, to read the PR text from the API and require it to mention an open issue, which will prevent it from being merged without containing the expected text.

    However, as for closing a pull request without merging it, such as if the submitted decides that the change is no longer necessary or should not have been made, it's not possible to prevent the user from doing so. Such a policy wouldn't be helpful, since it would force users to leave unwanted pull requests open.