Skip to content

Commit d57b0dc

Browse files
authored
chore: gate pull requests (#1412)
1 parent 6fd7656 commit d57b0dc

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Gate PRs to collaborators
2+
3+
on:
4+
pull_request_target:
5+
types: [opened, reopened]
6+
7+
permissions:
8+
pull-requests: write
9+
issues: write
10+
11+
jobs:
12+
close:
13+
if: ${{ !contains('OWNER,MEMBER,COLLABORATOR', github.event.pull_request.author_association) }}
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Comment
17+
uses: actions/github-script@v7
18+
with:
19+
script: |
20+
const pr = context.payload.pull_request;
21+
await github.rest.issues.createComment({
22+
owner: context.repo.owner,
23+
repo: context.repo.repo,
24+
issue_number: pr.number,
25+
body: `This repo doesn't accept PRs from non-collaborators. Open an issue instead or contact the team. Auto-closing.`
26+
});
27+
28+
- name: Close PR
29+
uses: actions/github-script@v7
30+
with:
31+
script: |
32+
const pr = context.payload.pull_request;
33+
await github.rest.pulls.update({
34+
owner: context.repo.owner,
35+
repo: context.repo.repo,
36+
pull_number: pr.number,
37+
state: 'closed'
38+
});

0 commit comments

Comments
 (0)