Skip to content

Commit f80f8d1

Browse files
committed
Soruce_Branch_Validation
1 parent 35442a6 commit f80f8d1

1 file changed

Lines changed: 54 additions & 0 deletions

File tree

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: Check PR Source Branch
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize, reopened, edited]
6+
7+
permissions:
8+
pull-requests: write
9+
content: read
10+
11+
jobs:
12+
check-source-branch:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout repository
16+
uses: actions/checkout@v4.2.2
17+
18+
- name: Set up Python
19+
uses: actions/setup-python@v2
20+
with:
21+
python-version: '3.x'
22+
23+
- name: Install dependencies
24+
run: pip install pyyaml PyGithub
25+
26+
- name: Run source branch check
27+
env:
28+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
29+
PR_NUMBER: ${{ github.event.pull_request.number }}
30+
SOURCE_BRANCH: ${{ github.head_ref }}
31+
REPO_NAME: ${{ github.repository }}
32+
run: |
33+
python <<EOF
34+
import os
35+
from github import Github
36+
37+
token = os.environ['GITHUB_TOKEN']
38+
repo_name = os.environ['REPO_NAME']
39+
pr_number = int(os.environ['PR_NUMBER'])
40+
source_branch = os.environ['SOURCE_BRANCH']
41+
42+
if source_branch != "starlight-dev":
43+
g = Github(token)
44+
repo = g.get_repo(repo_name)
45+
pr = repo.get_pull(pr_number)
46+
pr.create_issue_comment(
47+
f"This pull request must be opened from the `starlight-dev` branch.\n"
48+
f"Current: `{source_branch}`"
49+
)
50+
print(f"Invalid source branch: {source_branch}")
51+
exit(1)
52+
else:
53+
print(f"Source branch is valid: {source_branch}")
54+
EOF

0 commit comments

Comments
 (0)