Skip to content
Open
Changes from 1 commit
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
51 changes: 51 additions & 0 deletions .github/workflows/close-org-prs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Close PRs from Orgs

on:
pull_request_target:
Comment thread
davidism marked this conversation as resolved.
types: [opened, reopened, synchronize]

permissions:
pull-requests: write
issues: write
Comment thread
john0isaac marked this conversation as resolved.
Outdated

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 isFork = pr.head.repo.full_name !== pr.base.repo.full_name;
const forkOwnerType = pr.head.repo.owner.type;
if (isFork && forkOwnerType === 'Organization') {
Comment thread
davidism marked this conversation as resolved.
Outdated
// Add 'invalid' label
Comment thread
davidism marked this conversation as resolved.
Outdated
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pr.number,
labels: ['invalid']
});
// Close the PR
await github.rest.pulls.update({
owner: context.repo.owner,
Comment thread
davidism marked this conversation as resolved.
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: "We don't allow pull requests from organization accounts. This PR has been closed."
Comment thread
john0isaac marked this conversation as resolved.
Outdated
});
// Lock the conversation
await github.rest.issues.lock({
Comment thread
davidism marked this conversation as resolved.
Outdated
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pr.number,
lock_reason: 'spam'
Comment thread
davidism marked this conversation as resolved.
Outdated
});
}