Skip to content

~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.

refactor: Create reusable AI reviewer script for easier testing

LearningCircuitb31ff6fec15c
diff --git a/.github/workflows/ai-code-reviewer.yml b/.github/workflows/ai-code-reviewer.yml
index 9e9d9cf397..b958ac4e0d 100644
--- a/.github/workflows/ai-code-reviewer.yml
+++ b/.github/workflows/ai-code-reviewer.yml
@@ -33,42 +33,15 @@ jobs:
- name: Security Review via API
id: review
run: |
- # Build the request
- curl -s -X POST "https://openrouter.ai/api/v1/chat/completions" \
- -H "Content-Type: application/json" \
- -H "Authorization: Bearer ${{ secrets.OPENROUTER_API_KEY }}" \
- -H "HTTP-Referer: https://github.com/${{ github.repository }}" \
- -H "X-Title: AI Security Review" \
- -d '{
- "model": "z-ai/glm-4.6",
- "messages": [
- {
- "role": "system",
- "content": "You are a helpful security expert reviewing pull requests. Respond ONLY with valid JSON containing status, issues, warnings, and suggestions arrays."
- },
- {
- "role": "user",
- "content": "Analyze this code diff for security vulnerabilities: ${{ steps.diff.outputs.diff }}\n\nRespond with JSON: {\"status\":\"pass|fail|warning\",\"critical_issues\":[],\"warnings\":[],\"suggestions\":[]}"
- }
- ],
- "temperature": 0.1,
- "max_tokens": 2000
- }' > response.json
+ # Use the AI reviewer script
+ RESPONSE=$(./github/scripts/ai-reviewer.sh "security" "${{ steps.diff.outputs.diff }}" "${{ secrets.OPENROUTER_API_KEY }}")
+ echo "AI Response: $RESPONSE"
# Parse response
- if [ ! -s response.json ]; then
- echo "status=fail" >> $GITHUB_OUTPUT
- echo "No API response - check OPENROUTER_API_KEY secret"
- exit 1
- fi
-
- CONTENT=$(cat response.json | jq -r '.choices[0].message.content // "error"')
- echo "AI Response: $CONTENT"
-
- STATUS=$(echo "$CONTENT" | jq -r '.status // "fail"')
+ STATUS=$(echo "$RESPONSE" | jq -r '.status // "fail"')
echo "status=$STATUS" >> $GITHUB_OUTPUT
- # Create comment
+ # Log result
if [ "$STATUS" = "fail" ]; then
echo "🔒 Security issues found - please review"
elif [ "$STATUS" = "warning" ]; then
@@ -138,29 +111,12 @@ jobs:
- name: Performance Review via API
id: review
run: |
- curl -s -X POST "https://openrouter.ai/api/v1/chat/completions" \
- -H "Content-Type: application/json" \
- -H "Authorization: Bearer ${{ secrets.OPENROUTER_API_KEY }}" \
- -H "HTTP-Referer: https://github.com/${{ github.repository }}" \
- -H "X-Title: AI Performance Review" \
- -d '{
- "model": "z-ai/glm-4.6",
- "messages": [
- {
- "role": "system",
- "content": "You are a helpful performance expert reviewing pull requests. Respond ONLY with valid JSON containing status, issues, warnings, and suggestions arrays."
- },
- {
- "role": "user",
- "content": "Analyze this code diff for performance issues: ${{ steps.diff.outputs.diff }}\n\nRespond with JSON: {\"status\":\"pass|fail|warning\",\"critical_issues\":[],\"warnings\":[],\"suggestions\":[]}"
- }
- ],
- "temperature": 0.1,
- "max_tokens": 2000
- }' > response.json
-
- CONTENT=$(cat response.json | jq -r '.choices[0].message.content // "error"')
- STATUS=$(echo "$CONTENT" | jq -r '.status // "fail"')
+ # Use the AI reviewer script
+ RESPONSE=$(./github/scripts/ai-reviewer.sh "performance" "${{ steps.diff.outputs.diff }}" "${{ secrets.OPENROUTER_API_KEY }}")
+ echo "AI Response: $RESPONSE"
+
+ # Parse response
+ STATUS=$(echo "$RESPONSE" | jq -r '.status // "fail"')
echo "status=$STATUS" >> $GITHUB_OUTPUT
- name: Post Performance Review Comment
@@ -222,29 +178,12 @@ jobs:
- name: Code Quality Review via API
id: review
run: |
- curl -s -X POST "https://openrouter.ai/api/v1/chat/completions" \
- -H "Content-Type: application/json" \
- -H "Authorization: Bearer ${{ secrets.OPENROUTER_API_KEY }}" \
- -H "HTTP-Referer: https://github.com/${{ github.repository }}" \
- -H "X-Title: AI Code Quality Review" \
- -d '{
- "model": "z-ai/glm-4.6",
- "messages": [
- {
- "role": "system",
- "content": "You are a helpful code quality expert reviewing pull requests. Respond ONLY with valid JSON containing status, issues, warnings, and suggestions arrays."
- },
- {
- "role": "user",
- "content": "Analyze this code diff for quality issues: ${{ steps.diff.outputs.diff }}\n\nRespond with JSON: {\"status\":\"pass|fail|warning\",\"critical_issues\":[],\"warnings\":[],\"suggestions\":[]}"
- }
- ],
- "temperature": 0.1,
- "max_tokens": 2000
- }' > response.json
-
- CONTENT=$(cat response.json | jq -r '.choices[0].message.content // "error"')
- STATUS=$(echo "$CONTENT" | jq -r '.status // "fail"')
+ # Use the AI reviewer script
+ RESPONSE=$(./github/scripts/ai-reviewer.sh "quality" "${{ steps.diff.outputs.diff }}" "${{ secrets.OPENROUTER_API_KEY }}")
+ echo "AI Response: $RESPONSE"
+
+ # Parse response
+ STATUS=$(echo "$RESPONSE" | jq -r '.status // "fail"')
echo "status=$STATUS" >> $GITHUB_OUTPUT
- name: Post Code Quality Review Comment
@@ -304,29 +243,12 @@ jobs:
- name: Custom Requirements Review via API
id: review
run: |
- curl -s -X POST "https://openrouter.ai/api/v1/chat/completions" \
- -H "Content-Type: application/json" \
- -H "Authorization: Bearer ${{ secrets.OPENROUTER_API_KEY }}" \
- -H "HTTP-Referer: https://github.com/${{ github.repository }}" \
- -H "X-Title: AI Custom Requirements Review" \
- -d '{
- "model": "z-ai/glm-4.6",
- "messages": [
- {
- "role": "system",
- "content": "You are reviewing pull requests for custom team requirements. Respond ONLY with valid JSON containing status, issues, warnings, and suggestions arrays."
- },
- {
- "role": "user",
- "content": "Analyze this code diff for team requirements: ${{ steps.diff.outputs.diff }}\n\nRespond with JSON: {\"status\":\"pass|fail|warning\",\"critical_issues\":[],\"warnings\":[],\"suggestions\":[]}"
- }
- ],
- "temperature": 0.1,
- "max_tokens": 2000
- }' > response.json
-
- CONTENT=$(cat response.json | jq -r '.choices[0].message.content // "error"')
- STATUS=$(echo "$CONTENT" | jq -r '.status // "fail"')
+ # Use the AI reviewer script
+ RESPONSE=$(./github/scripts/ai-reviewer.sh "custom" "${{ steps.diff.outputs.diff }}" "${{ secrets.OPENROUTER_API_KEY }}")
+ echo "AI Response: $RESPONSE"
+
+ # Parse response
+ STATUS=$(echo "$RESPONSE" | jq -r '.status // "fail"')
echo "status=$STATUS" >> $GITHUB_OUTPUT
- name: Post Custom Requirements Review Comment
diff --git a/github/scripts/ai-reviewer.sh b/github/scripts/ai-reviewer.sh
new file mode 100755
index 0000000000..bead4a2ef6
--- /dev/null
+++ b/github/scripts/ai-reviewer.sh
@@ -0,0 +1,89 @@
+#!/bin/bash
+
+# AI Code Reviewer Script
+# Usage: ./ai-reviewer.sh <REVIEW_TYPE> <DIFF_CONTENT> <API_KEY>
+# REVIEW_TYPE: security, performance, quality, custom
+# DIFF_CONTENT: The git diff content
+# API_KEY: OpenRouter API key
+
+set -e
+
+REVIEW_TYPE="$1"
+DIFF_CONTENT="$2"
+API_KEY="$3"
+
+if [ -z "$REVIEW_TYPE" ] || [ -z "$DIFF_CONTENT" ] || [ -z "$API_KEY" ]; then
+ echo "Usage: $0 <REVIEW_TYPE> <DIFF_CONTENT> <API_KEY>"
+ exit 1
+fi
+
+# Set prompts based on review type
+case "$REVIEW_TYPE" in
+ "security")
+ SYSTEM_PROMPT="You are a helpful security expert reviewing pull requests. Respond ONLY with valid JSON containing status, issues, warnings, and suggestions arrays."
+ USER_PROMPT="Analyze this code diff for security vulnerabilities and respond with JSON: {\"status\":\"pass|fail|warning\",\"critical_issues\":[],\"warnings\":[],\"suggestions\":[]}"
+ ;;
+ "performance")
+ SYSTEM_PROMPT="You are a helpful performance expert reviewing pull requests. Respond ONLY with valid JSON containing status, issues, warnings, and suggestions arrays."
+ USER_PROMPT="Analyze this code diff for performance issues and respond with JSON: {\"status\":\"pass|fail|warning\",\"critical_issues\":[],\"warnings\":[],\"suggestions\":[]}"
+ ;;
+ "quality")
+ SYSTEM_PROMPT="You are a helpful code quality expert reviewing pull requests. Respond ONLY with valid JSON containing status, issues, warnings, and suggestions arrays."
+ USER_PROMPT="Analyze this code diff for quality issues and respond with JSON: {\"status\":\"pass|fail|warning\",\"critical_issues\":[],\"warnings\":[],\"suggestions\":[]}"
+ ;;
+ "custom")
+ SYSTEM_PROMPT="You are reviewing pull requests for custom team requirements. Respond ONLY with valid JSON containing status, issues, warnings, and suggestions arrays."
+ USER_PROMPT="Analyze this code diff for team requirements and respond with JSON: {\"status\":\"pass|fail|warning\",\"critical_issues\":[],\"warnings\":[],\"suggestions\":[]}"
+ ;;
+ *)
+ echo "Error: Unknown review type '$REVIEW_TYPE'. Use: security, performance, quality, or custom"
+ exit 1
+ ;;
+esac
+
+# Prepare the full user message with the diff
+FULL_USER_PROMPT="$USER_PROMPT\n\nCode diff to analyze:\n$DIFF_CONTENT"
+
+# Make API call to OpenRouter
+RESPONSE=$(curl -s -X POST "https://openrouter.ai/api/v1/chat/completions" \
+ -H "Content-Type: application/json" \
+ -H "Authorization: Bearer $API_KEY" \
+ -d "{
+ \"model\": \"z-ai/glm-4.6\",
+ \"messages\": [
+ {
+ \"role\": \"system\",
+ \"content\": \"$SYSTEM_PROMPT\"
+ },
+ {
+ \"role\": \"user\",
+ \"content\": \"$FULL_USER_PROMPT\"
+ }
+ ],
+ \"temperature\": 0.1,
+ \"max_tokens\": 2000
+ }")
+
+# Check if API call was successful
+if [ -z "$RESPONSE" ]; then
+ echo '{"status":"fail","critical_issues":[{"type":"api","message":"API call failed - no response"}],"warnings":[],"suggestions":[]}'
+ exit 1
+fi
+
+# Extract and validate the content
+CONTENT=$(echo "$RESPONSE" | jq -r '.choices[0].message.content // "error"')
+
+if [ "$CONTENT" = "error" ]; then
+ echo '{"status":"fail","critical_issues":[{"type":"api","message":"Invalid API response format"}],"warnings":[],"suggestions":[]}'
+ exit 1
+fi
+
+# Validate that the response is valid JSON
+if ! echo "$CONTENT" | jq . >/dev/null 2>&1; then
+ # If AI response is not valid JSON, create a fallback response
+ STATUS=$(echo "$CONTENT" | grep -o '"status":"[^"]*"' | head -1 | cut -d'"' -f4 || echo "fail")
+ echo "{\"status\":\"$STATUS\",\"critical_issues\":[{\"type\":\"parsing\",\"message\":\"AI response could not be parsed as JSON. Raw response: $CONTENT\"}],\"warnings\":[],\"suggestions\":[]}"
+else
+ # Return the valid JSON response
+ echo "$CONTENT"
+fi
\ No newline at end of file