-
Notifications
You must be signed in to change notification settings - Fork 3.8k
97 lines (87 loc) · 3.74 KB
/
opencode-review.yml
File metadata and controls
97 lines (87 loc) · 3.74 KB
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
name: Code Review
on:
pull_request_target:
types: [opened, synchronize, reopened, ready_for_review]
issue_comment:
types: [created, edited]
permissions:
pull-requests: read
statuses: write
jobs:
skip-on-comment:
name: Skip review via skip buildall comment
runs-on: ubuntu-latest
if: >
github.event_name == 'issue_comment' &&
github.event.issue.pull_request != null &&
contains(github.event.comment.body, 'skip buildall')
steps:
- name: Check user permission and mark review as success
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REPO: ${{ github.repository }}
COMMENT_USER_ID: ${{ github.event.comment.user.id }}
PR_NUMBER: ${{ github.event.issue.number }}
run: |
PR_INFO=$(gh api repos/${REPO}/pulls/${PR_NUMBER})
HEAD_SHA=$(echo "${PR_INFO}" | jq -r '.head.sha')
TARGET_BRANCH=$(echo "${PR_INFO}" | jq -r '.base.ref')
ALLOWED=false
if [[ "${COMMENT_USER_ID}" == '27881198' || "${COMMENT_USER_ID}" == '37901441' || "${COMMENT_USER_ID}" == '61408379' ]]; then
ALLOWED=true
elif [[ "${COMMENT_USER_ID}" == '9208457' && "${TARGET_BRANCH}" == *'branch-2.1'* ]]; then
ALLOWED=true
elif [[ "${COMMENT_USER_ID}" == '98214048' && "${TARGET_BRANCH}" == *'branch-3.0'* ]]; then
ALLOWED=true
elif [[ "${COMMENT_USER_ID}" == '101034200' && "${TARGET_BRANCH}" == *'branch-3.1'* ]]; then
ALLOWED=true
elif [[ ("${COMMENT_USER_ID}" == '9208457' || "${COMMENT_USER_ID}" == '2899462') && "${TARGET_BRANCH}" == *'branch-4.0'* ]]; then
ALLOWED=true
elif [[ "${COMMENT_USER_ID}" == '9208457' && "${TARGET_BRANCH}" == *'branch-4.1'* ]]; then
ALLOWED=true
fi
if [[ "${ALLOWED}" != 'true' ]]; then
echo "COMMENT_USER_ID ${COMMENT_USER_ID} is not allowed to skip code review."
exit 0
fi
echo "COMMENT_USER_ID ${COMMENT_USER_ID} is allowed to skip code review for ${TARGET_BRANCH}."
gh api repos/${REPO}/statuses/${HEAD_SHA} \
-X POST \
-f state="success" \
-f context='code-review' \
-f description="Code review skipped via 'skip buildall' comment." \
-f target_url="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
sync-status:
name: Sync review status
runs-on: ubuntu-latest
timeout-minutes: 120
if: github.event_name == 'pull_request_target'
steps:
- name: Check automated review decision for current PR head
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REPO: ${{ github.repository }}
PR_NUMBER: ${{ github.event.pull_request.number }}
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
run: |
STATUSES=$(gh api --paginate repos/${REPO}/commits/${HEAD_SHA}/status)
review_state=$(printf '%s' "$STATUSES" | jq -r '
([ .statuses[]
| select(.context == "code-review")
]
| sort_by(.created_at)
| last
| .state) // ""
')
state="pending"
summary="Trigger /review to start automated review for ${HEAD_SHA}."
if [ "$review_state" = "success" ]; then
state="success"
summary="Automated review was triggered for ${HEAD_SHA}."
fi
gh api repos/${REPO}/statuses/${HEAD_SHA} \
-X POST \
-f state="${state}" \
-f context='code-review' \
-f description="${summary}" \
-f target_url="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"