-
Notifications
You must be signed in to change notification settings - Fork 8
70 lines (58 loc) · 1.99 KB
/
kube-actions.yaml
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
name: PR Actions
on:
issue_comment:
types: [created]
pull_request:
types: [labeled]
env:
GH_TOKEN: ${{ secrets.AGENT_TOKEN }}
jobs:
handle-comments:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.x'
- name: Install yq
run: pip install yq
- name: Handle PR Comments
id: handle_comments
run: |
COMMENT_BODY=$(jq -r '.comment.body' $GITHUB_EVENT_PATH)
PR_NUMBER=$(jq -r '.issue.number' $GITHUB_EVENT_PATH)
COMMENT_USER=$(jq -r '.comment.user.login' $GITHUB_EVENT_PATH)
echo $GITHUB_EVENT_PATH
echo $COMMENT_BODY
echo $PR_NUMBER
echo $COMMENT_USER
OWNER_FILE=$(cat OWNERS)
if [[ "$COMMENT_BODY" == "/lgtm" ]]; then
gh pr edit $PR_NUMBER --add-label lgtm
elif [[ "$COMMENT_BODY" == "/approve" ]]; then
APPROVERS=$(echo "$OWNER_FILE" | yq e '.approvers[]' -)
if echo "$APPROVERS" | grep -q "$COMMENT_USER"; then
gh pr edit $PR_NUMBER --add-label approved
else
echo "User $COMMENT_USER is not authorized to approve"
exit 1
fi
elif [[ "$COMMENT_BODY" == "/kind feature" ]]; then
gh pr edit $PR_NUMBER --add-label feature
elif [[ "$COMMENT_BODY" == "/kind bug" ]]; then
gh pr edit $PR_NUMBER --add-label bug
elif [[ "$COMMENT_BODY" == "/kind cleanup" ]]; then
gh pr edit $PR_NUMBER --add-label cleanup
else
echo "$COMMENT_BODY is not supported"
exit 1
fi
- name: Merge PR if lgtmed and approved
run: |
PR_NUMBER=$(jq -r '.issue.number' $GITHUB_EVENT_PATH)
LABELS=$(gh pr view $PR_NUMBER --json labels --jq '.labels[].name')
if [[ "$LABELS" == *"lgtm"* && "$LABELS" == *"approved"* ]]; then
gh pr merge $PR_NUMBER --merge
fi