-
Notifications
You must be signed in to change notification settings - Fork 5
31 lines (25 loc) · 1007 Bytes
/
validate_pr_source.yml
File metadata and controls
31 lines (25 loc) · 1007 Bytes
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
name: Validate main branch PR source
on:
pull_request_target:
branches: [main]
types: [opened, reopened, synchronize]
permissions:
contents: read
pull-requests: write
issues: write
jobs:
validate-pr-source:
if: ${{ github.event.pull_request.head.ref != 'dev' || github.event.pull_request.head.repo.full_name != github.repository }}
runs-on: ubuntu-latest
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: Comment and close PR
run: |
HEAD_REF="${{ github.event.pull_request.head.ref }}"
HEAD_REPO="${{ github.event.pull_request.head.repo.full_name }}"
PR_NUMBER="${{ github.event.pull_request.number }}"
echo "Closing PR #$PR_NUMBER from invalid source: $HEAD_REPO / $HEAD_REF"
gh pr comment "$PR_NUMBER" \
--body "This PR targets **main**, but only PRs from **dev** in this repository are allowed. Detected source: **$HEAD_REPO:$HEAD_REF**."
gh pr close "$PR_NUMBER"