-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
95 lines (84 loc) · 3.04 KB
/
Copy pathcodex-review.yml
File metadata and controls
95 lines (84 loc) · 3.04 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
name: Codex Review
on:
issue_comment:
types: [created]
pull_request_review_comment:
types: [created]
pull_request:
types: [review_requested]
permissions:
contents: read
issues: read
pull-requests: read
jobs:
codex-review:
runs-on: ubuntu-latest
steps:
- name: Parse review command
id: command
shell: bash
env:
EVENT_NAME: ${{ github.event_name }}
COMMENT_BODY: ${{ github.event.comment.body }}
COMMENT_USER: ${{ github.event.comment.user.login }}
ISSUE_NUMBER: ${{ github.event.issue.number }}
ISSUE_PR_URL: ${{ github.event.issue.pull_request.url }}
PR_NUMBER: ${{ github.event.pull_request.number }}
REQUESTED_REVIEWER: ${{ github.event.requested_reviewer.login }}
SENDER_LOGIN: ${{ github.event.sender.login }}
run: |
set -euo pipefail
if [ "$EVENT_NAME" = "pull_request" ]; then
if [ "${REQUESTED_REVIEWER:-}" != "xingguangcuicanbot" ]; then
echo "matched=false" >> "$GITHUB_OUTPUT"
exit 0
fi
NUMBER="$PR_NUMBER"
REQUEST_USERNAME="${SENDER_LOGIN:-}"
else
if ! grep -Eq '(^|[[:space:]])/codex[[:space:]]+review([[:space:]]|$)' <<<"$COMMENT_BODY"; then
echo "matched=false" >> "$GITHUB_OUTPUT"
exit 0
fi
if [ "$EVENT_NAME" = "issue_comment" ]; then
if [ -z "${ISSUE_PR_URL:-}" ]; then
echo "matched=false" >> "$GITHUB_OUTPUT"
exit 0
fi
NUMBER="$ISSUE_NUMBER"
else
NUMBER="$PR_NUMBER"
fi
REQUEST_USERNAME="${COMMENT_USER:-}"
fi
if [ -z "${NUMBER:-}" ]; then
echo "::error::cannot resolve pull request number"
exit 1
fi
echo "matched=true" >> "$GITHUB_OUTPUT"
echo "repo=${GITHUB_REPOSITORY}" >> "$GITHUB_OUTPUT"
echo "username=${REQUEST_USERNAME}" >> "$GITHUB_OUTPUT"
echo "number=${NUMBER}" >> "$GITHUB_OUTPUT"
- name: Call reviewer service
if: steps.command.outputs.matched == 'true'
shell: bash
env:
REVIEW_SERVER_URL: ${{ secrets.CODEX_REVIEW_SERVER_URL }}
REPO: ${{ steps.command.outputs.repo }}
REQUEST_USERNAME: ${{ steps.command.outputs.username }}
PR_NUMBER: ${{ steps.command.outputs.number }}
run: |
set -euo pipefail
if [ -z "${REVIEW_SERVER_URL:-}" ]; then
echo "::error::missing secret CODEX_REVIEW_SERVER_URL"
exit 1
fi
payload=$(jq -n \
--arg repo "$REPO" \
--arg request_username "$REQUEST_USERNAME" \
--argjson pr_number "$PR_NUMBER" \
'{repo:$repo, request_username:$request_username, pr_number:$pr_number}')
curl -fsSL \
-H 'Content-Type: application/json' \
-d "$payload" \
"${REVIEW_SERVER_URL%/}/review"