Skip to content

Commit 60fa3a6

Browse files
committed
ci: better context creation
1 parent 62637b0 commit 60fa3a6

1 file changed

Lines changed: 30 additions & 12 deletions

File tree

.github/workflows/ai-review.yml

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ jobs:
2323
if: github.event.pull_request.draft == false
2424
runs-on: ubuntu-latest
2525

26+
env:
27+
MODEL: deepseek-r1:14b
28+
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/)'
29+
2630
steps:
2731
- name: Checkout
2832
uses: actions/checkout@v4
@@ -40,21 +44,32 @@ jobs:
4044
4145
- name: Pull model
4246
run: |
43-
ollama pull deepseek-r1:14b
47+
ollama pull $MODEL
4448
4549
- name: Build LLM context
4650
run: |
4751
git fetch origin main
4852
49-
FILES=$(git diff --name-only origin/main...HEAD)
53+
FILES=$(git diff --name-status origin/main...HEAD | awk '{print $1 "|" $2}')
5054
5155
> prompt.txt
5256
53-
for file in $FILES; do
54-
echo "===== FILE: $file =====" >> prompt.txt
55-
cat "$file" >> prompt.txt 2>/dev/null || true
56-
echo "" >> prompt.txt
57-
done
57+
while IFS="|" read -r status file; do
58+
[ -z "$file" ] && continue
59+
60+
# Respect paths filter
61+
if ! [[ "$file" =~ $INCLUDE_REGEX ]]; then
62+
continue
63+
fi
64+
65+
# Only include content for MODIFIED files
66+
if [[ "$status" == "M" ]]; then
67+
echo "===== FILE: $file =====" >> prompt.txt
68+
cat "$file" >> prompt.txt 2>/dev/null || true
69+
echo "" >> prompt.txt
70+
fi
71+
72+
done <<< "$FILES"
5873
5974
echo "===== DIFF =====" >> prompt.txt
6075
git diff origin/main...HEAD >> prompt.txt
@@ -145,11 +160,14 @@ jobs:
145160
echo "$PROMPT"
146161
147162
RESPONSE=$(curl -s http://localhost:11434/api/generate \
148-
-d "$(jq -n --arg prompt "$PROMPT" '{
149-
model: "deepseek-r1:14b",
150-
prompt: $prompt,
151-
stream: false
152-
}')")
163+
-d "$(jq -n \
164+
--arg model "$MODEL" \
165+
--arg prompt "$PROMPT" \
166+
'{
167+
model: $model,
168+
prompt: $prompt,
169+
stream: false
170+
}')")
153171
154172
echo "$RESPONSE" | jq -r '.response' > review.txt
155173

0 commit comments

Comments
 (0)