-
Notifications
You must be signed in to change notification settings - Fork 765
180 lines (163 loc) · 7.8 KB
/
Copy pathcodex-pr-review.yml
File metadata and controls
180 lines (163 loc) · 7.8 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
name: Codex PR Review
on:
pull_request_target:
types: [opened, reopened, ready_for_review, synchronize, labeled]
concurrency:
group: codex-pr-review-${{ github.event.pull_request.number }}
cancel-in-progress: true
permissions:
contents: read
jobs:
pr-review:
# Review all non-draft human PRs by default. The workflow restores the
# trusted prompt from the base SHA before running the write-token bot.
if: |
github.event.pull_request.draft == false &&
!endsWith(github.actor, '[bot]') &&
!contains(github.event.pull_request.labels.*.name, 'bot-skip') &&
vars.CODEX_BOT_ENABLED == 'true'
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
outputs:
review_result: ${{ steps.run_codex.outputs.final-message }}
steps:
- name: Check bot review state
id: check_bot
uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b # v7
with:
script: |
const marker = "*Open-CoDesign Bot*";
const allowedLogins = (process.env.BOT_LOGINS || "github-actions[bot]")
.split(",").map((v) => v.trim()).filter(Boolean);
const currentHeadSha = context.payload.pull_request.head.sha;
const reviews = await github.paginate(
github.rest.pulls.listReviews,
{
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.payload.pull_request.number,
per_page: 100
}
);
const botReviews = reviews
.filter((r) => {
if (!(r?.body || "").includes(marker)) return false;
const u = r.user;
if (!u || u.type !== "Bot") return false;
return allowedLogins.includes(u.login);
})
.sort((a, b) => {
const at = new Date(a.submitted_at || a.created_at || 0).getTime();
const bt = new Date(b.submitted_at || b.created_at || 0).getTime();
if (bt !== at) return bt - at;
return (b.id || 0) - (a.id || 0);
});
const latest = botReviews[0];
const hasReviewForCurrentHead = botReviews.some((r) => r.commit_id === currentHeadSha);
const isFollowUp = Boolean(latest?.commit_id && latest.commit_id !== currentHeadSha);
core.setOutput("current_head_sha", currentHeadSha);
core.setOutput("has_review_for_current_head", hasReviewForCurrentHead ? "true" : "false");
core.setOutput("latest_bot_review_id", latest ? String(latest.id) : "");
core.setOutput("latest_bot_review_commit", latest?.commit_id || "");
core.setOutput("is_follow_up_review", isFollowUp ? "true" : "false");
env:
BOT_LOGINS: ${{ vars.BOT_LOGINS }}
- name: Checkout repository
if: steps.check_bot.outputs.has_review_for_current_head != 'true'
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
with:
ref: ${{ github.event.pull_request.base.sha }}
fetch-depth: 0
- name: Pre-fetch base and head refs
if: steps.check_bot.outputs.has_review_for_current_head != 'true'
run: |
git fetch --no-tags origin \
${{ github.event.pull_request.base.ref }} \
+refs/pull/${{ github.event.pull_request.number }}/head:refs/remotes/pull/${{ github.event.pull_request.number }}/head
- name: Restore trusted review prompt
if: steps.check_bot.outputs.has_review_for_current_head != 'true'
run: |
# This workflow runs under pull_request_target so it can post reviews.
# The checked-out merge ref is untrusted contributor content; never
# let a PR modify the prompt that receives write-token access.
git show "${{ github.event.pull_request.base.sha }}:.github/prompts/codex-pr-review.md" \
> .github/prompts/codex-pr-review.md
- name: Resolve review provider config
if: steps.check_bot.outputs.has_review_for_current_head != 'true'
id: review_config
shell: bash
env:
DEFAULT_API_KEY: ${{ secrets.OPENAI_API_KEY }}
DEFAULT_BASE_URL: ${{ secrets.OPENAI_BASE_URL }}
DEFAULT_MODEL: ${{ vars.OPENAI_MODEL }}
DEFAULT_EFFORT: ${{ vars.OPENAI_EFFORT }}
REVIEW_API_KEY: ${{ secrets.REVIEW_OPENAI_API_KEY }}
REVIEW_BASE_URL: ${{ secrets.REVIEW_OPENAI_BASE_URL }}
REVIEW_MODEL: ${{ vars.REVIEW_OPENAI_MODEL }}
REVIEW_EFFORT: ${{ vars.REVIEW_OPENAI_EFFORT }}
run: |
api_key="$REVIEW_API_KEY"
[ -n "$api_key" ] || api_key="$DEFAULT_API_KEY"
base_url="$REVIEW_BASE_URL"
[ -n "$base_url" ] || base_url="$DEFAULT_BASE_URL"
model="$REVIEW_MODEL"
[ -n "$model" ] || model="$DEFAULT_MODEL"
[ -n "$model" ] || model='gpt-5.4'
effort="$REVIEW_EFFORT"
[ -n "$effort" ] || effort="$DEFAULT_EFFORT"
[ -n "$effort" ] || effort='high'
is_deepseek='false'
case "$base_url" in
*api.deepseek.com*)
is_deepseek='true'
;;
esac
{
echo "api_key=$api_key"
echo "base_url=$base_url"
echo "model=$model"
echo "effort=$effort"
echo "is_deepseek=$is_deepseek"
} >> "$GITHUB_OUTPUT"
- name: Set up Node.js for DeepSeek review
if: steps.check_bot.outputs.has_review_for_current_head != 'true' && steps.review_config.outputs.is_deepseek == 'true'
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
with:
node-version: "20"
- name: Run DeepSeek for PR Review
if: steps.check_bot.outputs.has_review_for_current_head != 'true' && steps.review_config.outputs.is_deepseek == 'true'
env:
GH_TOKEN: ${{ github.token }}
GITHUB_TOKEN: ${{ github.token }}
CURRENT_HEAD_SHA: ${{ steps.check_bot.outputs.current_head_sha }}
LATEST_BOT_REVIEW_ID: ${{ steps.check_bot.outputs.latest_bot_review_id }}
LATEST_BOT_REVIEW_COMMIT: ${{ steps.check_bot.outputs.latest_bot_review_commit }}
IS_FOLLOW_UP_REVIEW: ${{ steps.check_bot.outputs.is_follow_up_review }}
DEEPSEEK_API_KEY: ${{ steps.review_config.outputs.api_key }}
DEEPSEEK_BASE_URL: ${{ steps.review_config.outputs.base_url }}
DEEPSEEK_MODEL: ${{ steps.review_config.outputs.model }}
DEEPSEEK_EFFORT: ${{ steps.review_config.outputs.effort }}
run: node .github/scripts/deepseek-pr-review.mjs
- name: Run Codex for PR Review
id: run_codex
if: steps.check_bot.outputs.has_review_for_current_head != 'true' && steps.review_config.outputs.is_deepseek != 'true'
uses: openai/codex-action@e0fdf01220eb9a88167c4898839d273e3f2609d1 # v1
env:
GH_TOKEN: ${{ github.token }}
GITHUB_TOKEN: ${{ github.token }}
CURRENT_HEAD_SHA: ${{ steps.check_bot.outputs.current_head_sha }}
LATEST_BOT_REVIEW_ID: ${{ steps.check_bot.outputs.latest_bot_review_id }}
LATEST_BOT_REVIEW_COMMIT: ${{ steps.check_bot.outputs.latest_bot_review_commit }}
IS_FOLLOW_UP_REVIEW: ${{ steps.check_bot.outputs.is_follow_up_review }}
with:
openai-api-key: ${{ steps.review_config.outputs.api_key }}
responses-api-endpoint: ${{ steps.review_config.outputs.base_url }}
model: ${{ steps.review_config.outputs.model }}
effort: ${{ steps.review_config.outputs.effort }}
sandbox: danger-full-access
safety-strategy: drop-sudo
prompt-file: .github/prompts/codex-pr-review.md
allow-bots: true
allow-users: '*'