-
Notifications
You must be signed in to change notification settings - Fork 1
57 lines (49 loc) · 2 KB
/
PR.yml
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
Pname: Auto Approve and Merge PR
on:
pull_request:
types:
- opened
- synchronize
- reopened
jobs:
auto_approve_merge:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '14'
- name: Install dependencies
run: npm install
- name: Check if all checks have passed
id: checks
run: |
checks=$(curl -s -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
"https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/commits" \
| jq -r '.[].commit.checks_url')
check_statuses=$(curl -s -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
$checks \
| jq -r '.[].status')
echo "Check statuses: $check_statuses"
if [[ ! "$check_statuses" =~ "failure" ]]; then
echo "All checks passed. Approving and merging PR."
echo "::set-output name=approved::true"
else
echo "Some checks failed. Not approving PR."
echo "::set-output name=approved::false"
fi
- name: Approve and Merge PR
if: steps.checks.outputs.approved == 'true'
run: |
curl -X POST \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
-H "Content-Type: application/json" \
-d '{"event": "APPROVE"}' \
"https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/reviews"
curl -X PUT \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
-H "Content-Type: application/json" \
-d '{"merge_method": "merge"}' \
"https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/merge"