Skip to content

Commit 858a716

Browse files
authored
chore(workflow): codereview.yml
1 parent 5a89e37 commit 858a716

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

.github/workflows/codereview.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: Auto-Approve Pull Requests
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize, reopened]
6+
schedule:
7+
- cron: '0 */6 * * *'
8+
workflow_dispatch:
9+
10+
jobs:
11+
auto-approve:
12+
runs-on: ubuntu-latest
13+
permissions:
14+
pull-requests: write
15+
16+
steps:
17+
- name: Checkout repository
18+
uses: actions/checkout@v3
19+
20+
- name: Auto-approve Pull Requests
21+
env:
22+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
23+
run: |
24+
import os
25+
from github import Github
26+
27+
def approve_pr(pr):
28+
pr.create_review(event='APPROVE', body='Automatically approved')
29+
print(f"Approved PR #{pr.number}")
30+
31+
g = Github(os.getenv('GITHUB_TOKEN'))
32+
repo = g.get_repo(os.getenv('GITHUB_REPOSITORY'))
33+
34+
if os.getenv('GITHUB_EVENT_NAME') == 'pull_request':
35+
pr_number = os.getenv('GITHUB_EVENT_PULL_REQUEST_NUMBER')
36+
pr = repo.get_pull(int(pr_number))
37+
approve_pr(pr)
38+
else:
39+
for pr in repo.get_pulls(state='open'):
40+
approve_pr(pr)
41+
42+
print("Auto-approval process completed successfully.")
43+
shell: python
44+

0 commit comments

Comments
 (0)