-
Notifications
You must be signed in to change notification settings - Fork 0
195 lines (175 loc) · 6.42 KB
/
codex-code-review.yml
File metadata and controls
195 lines (175 loc) · 6.42 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
name: Codex Code Review
on:
pull_request:
types: [opened, synchronize, ready_for_review]
workflow_dispatch:
inputs:
pr_number:
description: 'PR number to review'
required: true
type: number
jobs:
check-files:
name: Check Changed Files
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: read
outputs:
skip_codex: ${{ steps.check.outputs.skip }}
steps:
- name: Check for Codex workflow-only changes
id: check
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_NUMBER: ${{ github.event.pull_request.number || inputs.pr_number }}
run: |
FILES=$(gh pr view "$PR_NUMBER" --repo "${{ github.repository }}" --json files -q '.files[].path')
if echo "$FILES" | grep -qvE '^(\.github/workflows/codex-code-review\.yml|\.github/codex/)'; then
echo "PR contains non-Codex-review files - Codex will review"
echo "skip=false" >> "$GITHUB_OUTPUT"
else
echo "PR only modifies Codex review automation files - skipping self-review"
echo "skip=true" >> "$GITHUB_OUTPUT"
fi
codex-review:
name: Codex Review
needs: check-files
if: needs.check-files.outputs.skip_codex != 'true'
runs-on: ubuntu-latest
continue-on-error: true
permissions:
contents: read
pull-requests: write
env:
HAS_OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY != '' }}
steps:
- name: Checkout repository
uses: actions/checkout@v6
with:
ref: refs/pull/${{ github.event.pull_request.number || inputs.pr_number }}/merge
fetch-depth: 0
- name: Load pull request metadata
id: pr
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_NUMBER: ${{ github.event.pull_request.number || inputs.pr_number }}
run: |
gh pr view "$PR_NUMBER" --repo "${{ github.repository }}" \
--json number,baseRefName,baseRefOid,headRefName,headRefOid,author,isDraft \
> pr.json
{
echo "number=$(jq -r '.number' pr.json)"
echo "base_ref=$(jq -r '.baseRefName' pr.json)"
echo "base_sha=$(jq -r '.baseRefOid' pr.json)"
echo "head_ref=$(jq -r '.headRefName' pr.json)"
echo "head_sha=$(jq -r '.headRefOid' pr.json)"
echo "author=$(jq -r '.author.login' pr.json)"
echo "draft=$(jq -r '.isDraft' pr.json)"
} >> "$GITHUB_OUTPUT"
- name: Decide whether to run Codex
id: gate
env:
AUTHOR: ${{ steps.pr.outputs.author }}
IS_DRAFT: ${{ steps.pr.outputs.draft }}
HAS_OPENAI_API_KEY: ${{ env.HAS_OPENAI_API_KEY }}
run: |
if [ "$IS_DRAFT" = 'true' ]; then
{
echo 'run=false'
echo 'reason=Draft pull request'
} >> "$GITHUB_OUTPUT"
exit 0
fi
case "$AUTHOR" in
dependabot[bot]|renovate[bot]|github-actions[bot])
{
echo 'run=false'
echo 'reason=Bot-authored pull request'
} >> "$GITHUB_OUTPUT"
exit 0
;;
esac
if [ "$HAS_OPENAI_API_KEY" != 'true' ]; then
{
echo 'run=false'
echo 'reason=OPENAI_API_KEY is unavailable for this run'
} >> "$GITHUB_OUTPUT"
exit 0
fi
{
echo 'run=true'
echo 'reason=Review enabled'
} >> "$GITHUB_OUTPUT"
- name: Pre-fetch base and head refs
if: steps.gate.outputs.run == 'true'
run: |
git fetch --no-tags origin \
"${{ steps.pr.outputs.base_ref }}" \
"+refs/pull/${{ steps.pr.outputs.number }}/head"
- name: Run Codex Review
if: steps.gate.outputs.run == 'true'
id: run_codex
uses: openai/codex-action@v1
env:
PR_NUMBER: ${{ steps.pr.outputs.number }}
PR_BASE_SHA: ${{ steps.pr.outputs.base_sha }}
PR_HEAD_SHA: ${{ steps.pr.outputs.head_sha }}
PR_AUTHOR: ${{ steps.pr.outputs.author }}
PR_HEAD_REF: ${{ steps.pr.outputs.head_ref }}
with:
openai-api-key: ${{ secrets.OPENAI_API_KEY }}
prompt-file: .github/codex/prompts/review.md
output-file: codex-review.json
output-schema-file: .github/codex/schemas/review-output.schema.json
codex-args: --full-auto
safety-strategy: drop-sudo
sandbox: read-only
- name: Post Codex review
if: steps.gate.outputs.run == 'true'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_NUMBER: ${{ steps.pr.outputs.number }}
run: |
jq -e '.event and .body' codex-review.json >/dev/null
jq -r '.body' codex-review.json > codex-review-body.md
REVIEW_EVENT=$(jq -r '.event' codex-review.json)
case "$REVIEW_EVENT" in
APPROVE) REVIEW_FLAG='--approve' ;;
REQUEST_CHANGES) REVIEW_FLAG='--request-changes' ;;
COMMENT) REVIEW_FLAG='--comment' ;;
*)
echo "::error::Unsupported review event: $REVIEW_EVENT"
exit 1
;;
esac
gh pr review "$PR_NUMBER" \
--repo "${{ github.repository }}" \
"$REVIEW_FLAG" \
--body-file codex-review-body.md
- name: Log skipped Codex review
if: steps.gate.outputs.run != 'true'
run: |
echo "Skipping Codex review"
echo "Reason: ${{ steps.gate.outputs.reason }}"
skip-notification:
name: Skip Notification
needs: check-files
if: needs.check-files.outputs.skip_codex == 'true'
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- name: Post skip notification
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_NUMBER: ${{ github.event.pull_request.number || inputs.pr_number }}
run: |
gh pr comment "$PR_NUMBER" --repo "${{ github.repository }}" --body "## Codex Code Review - Skipped
This PR only modifies Codex review automation files. Codex cannot review changes to its own workflow or prompt files.
**Alternative reviewers:**
- Claude Code Review
- CodeRabbit
- Human codeowner (@ANcpLua)
---
*This is expected behavior, not an error.*"