Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions .github/workflows/close-org-prs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Close PRs from Orgs

on:
pull_request_target:
types: [ opened ]

permissions:
pull-requests: write

jobs:
close-org-prs:
runs-on: ubuntu-latest
steps:
- name: Check if PR is from an org and close if so
uses: actions/github-script@v7
with:
script: |
const pr = context.payload.pull_request;
const isOwner = pr.head.repo.full_name !== pr.base.repo.full_name;
const forkOwnerType = pr.head.repo.owner.type;
if (isOwner && forkOwnerType === 'Organization') {
// Close the PR
await github.rest.pulls.update({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: pr.number,
state: 'closed'
});
// Leave a comment
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pr.number,
body: `Please don't open PRs from a fork owned by a different organization rather than your account. It causes GitHub to disable the ability for maintainers to push changes, so we can't update this to prepare it for merge.

To fix this:
1. Fork this project with your user account.
2. Push this branch there.
3. Create the PR again from that fork/branch.
`
});
}
Loading