-
Notifications
You must be signed in to change notification settings - Fork 0
76 lines (68 loc) · 2.48 KB
/
auto-merge-snyk.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
name: Auto Merge Snyk PRs
on:
pull_request:
types:
- opened
- synchronize
- reopened
jobs:
auto-merge:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Set up GitHub CLI
uses: actions/setup-gh@v3
- name: Get PR info
id: pr-info
run: |
pr_info=$(gh pr view ${{ github.event.pull_request.number }} --json title,author)
echo "$pr_info" | jq -r '.title' > pr_title.txt
echo "$pr_info" | jq -r '.author.login' > author.txt
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Check if PR title starts with [snyk]
id: check-snyk
run: |
pr_title=$(cat pr_title.txt)
if [[ "$pr_title" == \[snyk\]* ]]; then
echo "::set-output name=is_snyk::true"
else
echo "::set-output name=is_snyk::false"
fi
- name: Check if snyk-bot is a participant
id: check-participant
run: |
participants=$(gh pr view ${{ github.event.pull_request.number }} --json comments,reviewRequests,reviews -q '
[
.comments.nodes[].author.login,
.reviewRequests.nodes[].requestedReviewer.login,
.reviews.nodes[].author.login
] | unique'
)
echo "$participants" | jq -r '.[]' > participants.txt
if grep -q "snyk-bot" participants.txt; then
echo "::set-output name=is_snyk_bot_participant::true"
else
echo "::set-output name=is_snyk_bot_participant::false"
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Check if all checks passed
id: check-passed
run: |
checks=$(gh pr checks ${{ github.event.pull_request.number }} --json status -q '
.[] | select(.status != "completed" or .conclusion != "success") | .name'
)
if [[ -z "$checks" ]]; then
echo "::set-output name=checks_passed::true"
else
echo "::set-output name=checks_passed::false"
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Auto merge if conditions are met
if: steps.check-snyk.outputs.is_snyk == 'true' && steps.check-author.outputs.is_snyk_bot == 'true' && steps.check-participant.outputs.is_snyk_bot_participant == 'true' && steps.check-passed.outputs.checks_passed == 'true'
run: gh pr merge ${{ github.event.pull_request.number }} --merge
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}