-
-
Notifications
You must be signed in to change notification settings - Fork 77
39 lines (36 loc) · 1.31 KB
/
close-fork-pr.yml
File metadata and controls
39 lines (36 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
name: Close PRs from Forks
on:
pull_request_target:
types:
- opened
- synchronize
jobs:
check-fork:
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- name: Check if PR is from a fork
id: check
run: |
echo "PR head repo: ${{ github.event.pull_request.head.repo.full_name }}"
echo "Base repo: ${{ github.event.repository.full_name }}"
if [[ "${{ github.event.pull_request.head.repo.full_name }}" != "${{ github.event.repository.full_name }}" ]]; then
echo "PR is from a fork"
echo "is_fork=true" >> $GITHUB_ENV
else
echo "PR is not from a fork"
echo "is_fork=false" >> $GITHUB_ENV
fi
- name: Close PR and add comment
if: env.is_fork == 'true'
run: |
PR_NUMBER=${{ github.event.pull_request.number }}
GH_REPO=${{ github.repository }}
echo "Closing PR #$PR_NUMBER in repository $GH_REPO"
gh pr close \
"$PR_NUMBER" \
--repo "${{ github.repository }}" \
--comment "This PR has been closed because PRs from forks are not allowed. Please create a branch directly off the origin repository and resubmit your PR."
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}