-
-
Notifications
You must be signed in to change notification settings - Fork 154
222 lines (174 loc) · 6.27 KB
/
ai-review.yml
File metadata and controls
222 lines (174 loc) · 6.27 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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
name: 🦊 Code Review
on:
pull_request:
types: [ready_for_review, synchronize]
paths:
- ".github/workflows/**"
- "package.json"
- "react-native-keyboard-controller.podspec"
- "react-native.config.js"
- "android/**"
- "common/**"
- "ios/**"
- "src/**"
- "jest/**"
- "docs/docs/**"
- "docs/src/**"
- "docs/blog/**"
jobs:
review:
name: 🕵️ Finding bugs
if: github.event.pull_request.draft == false
runs-on: ubuntu-latest
env:
MODEL: deepseek-r1:14b
INCLUDE_REGEX: '^(\.github/workflows/|package\.json|react-native-keyboard-controller\.podspec|react-native\.config\.js|android/|common/|ios/|src/|jest/|docs/docs/|docs/src/|docs/blog/)'
concurrency:
group: ai-review-${{ github.event.pull_request.number }}
cancel-in-progress: true
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install Ollama
run: |
curl -fsSL https://ollama.com/install.sh | sh
- name: Start Ollama
run: |
ollama serve &
sleep 5
- name: Pull model
run: |
ollama pull $MODEL
- name: Build LLM context
run: |
git fetch origin main
FILES=$(git diff --name-status origin/main...HEAD | awk '{print $1 "|" $2}')
> prompt.txt
while IFS="|" read -r status file; do
[ -z "$file" ] && continue
# Ignore example / FabricExample anywhere
if [[ "$file" =~ (^|/)(example|FabricExample)(/|$) ]]; then
continue
fi
# Respect paths filter
if ! [[ "$file" =~ $INCLUDE_REGEX ]]; then
continue
fi
# Only include content for MODIFIED files
if [[ "$status" == "M" ]]; then
echo "===== FILE: $file =====" >> prompt.txt
cat "$file" >> prompt.txt 2>/dev/null || true
echo "" >> prompt.txt
fi
done <<< "$FILES"
echo "===== DIFF =====" >> prompt.txt
git diff origin/main...HEAD | \
awk '
/^diff --git/ {
skip = ($3 ~ /\/(example|FabricExample)\//)
}
!skip
' >> prompt.txt
- name: Run LLM review
run: |
PROMPT="
CHANGES:
$(cat prompt.txt)
---
You are a senior staff engineer performing a STRICT pull request code review.
You are NOT allowed to summarize or explain the changes.
If you output anything other than:
- a list of issues in the required format
- or exactly 'LGTM'
→ your response is INVALID.
Your ONLY goal is to detect REAL defects that will cause:
- runtime errors
- CI/CD failure
- incorrect program behavior
- security vulnerabilities
---
## HARD CONSTRAINTS (must follow exactly)
- Output MAXIMUM 2 issues
- If there are NO critical issues → output EXACTLY: LGTM
- Do NOT guess, speculate, or infer risk
- If not 100% sure → output LGTM
- Do NOT comment on style, naming, formatting, or architecture
- Do NOT suggest refactoring or improvements unless it fixes a real bug
- Do NOT provide general engineering advice
- Do NOT include reasoning, thinking, or analysis process
- Do NOT provide changes overview → only issues spotted during review
- Do NOT output anything except final result
---
## DETECTION PRIORITY (only these matter)
1. Code that will crash at runtime
2. Broken CI / build / scripts
3. Incorrect logic that changes behavior
4. Security issues that are clearly exploitable
5. Invalid assumptions that guarantee failure
---
## FORBIDDEN CONTENT
Reject these categories completely:
- 'best practices'
- 'consider improving'
- 'might be better'
- performance suggestions without measurable bug
- architectural opinions
- speculative risks
- changes overview
Examples of INVALID responses (DO NOT DO THIS):
- 'This PR introduces...'
- 'The changes include...'
- 'Here is a summary...'
- 'This adds a new feature...'
- Any explanation of what the code does
If you do this → you FAILED the task.
You MUST make a strict decision:
- If there is at least 1 REAL defect → output issues
- If there are 0 CERTAIN defects → output EXACTLY: LGTM
No other output is allowed.
Format:
1. **Title**
**Why**: ...
**Fix**: ...
"
echo "$PROMPT"
RESPONSE=$(curl -s http://localhost:11434/api/generate \
-d "$(jq -n \
--arg model "$MODEL" \
--arg prompt "$PROMPT" \
'{
model: $model,
prompt: $prompt,
stream: false
}')")
echo "$RESPONSE" | jq -r '.response' > review.txt
- name: Upsert PR comment
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const body = fs.readFileSync('review.txt', 'utf8');
const marker = '<!-- AI_REVIEW_COMMENT -->';
const finalBody = `${marker}\n${body}`;
const { data: comments } = await github.rest.issues.listComments({
...context.repo,
issue_number: context.issue.number,
});
const existing = comments.find(comment =>
comment.body && comment.body.includes(marker)
);
if (existing) {
await github.rest.issues.updateComment({
...context.repo,
comment_id: existing.id,
body: finalBody,
});
} else {
await github.rest.issues.createComment({
...context.repo,
issue_number: context.issue.number,
body: finalBody,
});
}