Closing PRs from forks

Hi folks,

We have a repo that we’re essentially making externally read-only, so we’d like to be able to automatically close PRs that are created from forks. PRs from branches on the same repo is fine, as this is someone internal who has good reason to be touching the repo.

Does anyone have suggestions for the best way to go about automatically closing PRs from forks?

In a repository, all the members who are Read permission can open PRs in this repository, but can’t merge the PRs. If your repository is public, the external users also have the Read permission to open PRs.
Currently, we have no easy methods to automatically close PRs from forks. As a workaround, you can try the following steps:

  • Setup a workflow runs on Scheduled events.
  • In the workflow, set a step to run the “List pull requests” API to get all the Open state PRs and list the PR numbers of the PRs that from externals/forks. Here you may need using jq to read and filter the data from the JSON-type Response body of the API.
  • Then set another step to run the “Update a pull request” API in a loop to close the PRs based on the PR numbers list.
1 Like

I’ve made an action to do this.

1 Like

Amazing, this looks like exactly what we need. I’ll try putting it in place and get back to you once we have it live!