fix: correct Ollama URL, API endpoint, and JSON construction in pr-review workflow
- Fix OLLAMA_URL to point at actual Ollama server (172.0.1.42:11434) - Fix API path from /v1/chat to /api/chat (Ollama native endpoint) - Fix response parsing from OpenAI format to Ollama native (.message.content) - Use jq to safely construct JSON bodies in both Analyze and Post steps - Add HTTP status code check and response body logging for diagnostics
This commit is contained in:
parent
d759486b51
commit
5e61d4f550
@ -32,25 +32,33 @@ jobs:
|
|||||||
- name: Analyze with Ollama
|
- name: Analyze with Ollama
|
||||||
if: steps.diff.outputs.diff_size > '0'
|
if: steps.diff.outputs.diff_size > '0'
|
||||||
env:
|
env:
|
||||||
OLLAMA_URL: http://172.0.0.29:3000/ollama/v1
|
OLLAMA_URL: http://172.0.1.42:11434
|
||||||
API_KEY: ${{ secrets.OLLAMA_API_KEY }}
|
|
||||||
run: |
|
run: |
|
||||||
DIFF_CONTENT=$(cat /tmp/pr_diff.txt)
|
DIFF_CONTENT=$(cat /tmp/pr_diff.txt)
|
||||||
PROMPT="Analyze the following code changes for completion, completeness, correctness, security issues, and best practices. PR Title: ${{ github.event.pull_request.title }}. Diff: $DIFF_CONTENT. Provide review with: 1) Completion check, 2) Completeness check, 3) Bugs/errors, 4) Security issues, 5) Best practices. Then give specific comments with suggested fixes."
|
PR_TITLE="${{ github.event.pull_request.title }}"
|
||||||
|
PROMPT="Analyze the following code changes for correctness, security issues, and best practices. PR Title: ${PR_TITLE}\n\nDiff:\n${DIFF_CONTENT}\n\nProvide a review with: 1) Summary, 2) Bugs/errors, 3) Security issues, 4) Best practices. Give specific comments with suggested fixes."
|
||||||
|
BODY=$(jq -n \
|
||||||
|
--arg model "qwen3-coder-next:latest" \
|
||||||
|
--arg content "$PROMPT" \
|
||||||
|
'{model: $model, messages: [{role: "user", content: $content}], stream: false}')
|
||||||
echo "Calling Ollama API..."
|
echo "Calling Ollama API..."
|
||||||
RESPONSE=$(curl -s -X POST "$OLLAMA_URL/chat" -H "Authorization: Bearer $API_KEY" -H "Content-Type: application/json" -d "{\"model\":\"qwen3-coder-next:latest\",\"messages\":[{\"role\":\"user\",\"content\":\"$PROMPT\"}],\"stream\":false}")
|
HTTP_CODE=$(curl -s -o /tmp/ollama_response.json -w "%{http_code}" \
|
||||||
echo "Response: $RESPONSE" > /tmp/ollama_response.txt
|
-X POST "$OLLAMA_URL/api/chat" \
|
||||||
echo "$RESPONSE" > /tmp/ollama_response.json
|
-H "Content-Type: application/json" \
|
||||||
echo "Response saved to /tmp/ollama_response.json"
|
-d "$BODY")
|
||||||
if [ -z "$RESPONSE" ]; then
|
echo "HTTP status: $HTTP_CODE"
|
||||||
echo "ERROR: Empty response from Ollama"
|
echo "Response body:"
|
||||||
|
cat /tmp/ollama_response.json
|
||||||
|
if [ "$HTTP_CODE" != "200" ]; then
|
||||||
|
echo "ERROR: Ollama returned HTTP $HTTP_CODE"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
REVIEW=$(echo "$RESPONSE" | jq -r '.choices[0].message.content // empty' 2>/dev/null || echo "Failed to parse jq response")
|
REVIEW=$(jq -r '.message.content // empty' /tmp/ollama_response.json)
|
||||||
echo "$REVIEW" > /tmp/pr_review.txt
|
|
||||||
if [ -z "$REVIEW" ]; then
|
if [ -z "$REVIEW" ]; then
|
||||||
echo "WARNING: No review content extracted"
|
echo "ERROR: No content in Ollama response"
|
||||||
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
echo "$REVIEW" > /tmp/pr_review.txt
|
||||||
|
|
||||||
- name: Post review comment
|
- name: Post review comment
|
||||||
if: success()
|
if: success()
|
||||||
@ -59,8 +67,14 @@ jobs:
|
|||||||
PR_NUMBER: ${{ github.event.pull_request.number }}
|
PR_NUMBER: ${{ github.event.pull_request.number }}
|
||||||
run: |
|
run: |
|
||||||
if [ -f "/tmp/pr_review.txt" ] && [ -s "/tmp/pr_review.txt" ]; then
|
if [ -f "/tmp/pr_review.txt" ] && [ -s "/tmp/pr_review.txt" ]; then
|
||||||
REVIEW_BODY=$(cat /tmp/pr_review.txt | head -c 65536)
|
REVIEW_BODY=$(head -c 65536 /tmp/pr_review.txt)
|
||||||
curl -s -X POST "http://172.0.0.29:3000/api/v1/repos/sarman/tftsr-devops_investigation/pulls/$PR_NUMBER/reviews" -H "Authorization: token $TF_TOKEN" -H "Content-Type: application/json" -d "{\"body\": \"🤖 Automated PR Review:\n\n$REVIEW_BODY\n\n---\n*this is an automated review from Ollama*\", \"event\": \"COMMENT\"}"
|
BODY=$(jq -n \
|
||||||
|
--arg body "🤖 Automated PR Review:\n\n${REVIEW_BODY}\n\n---\n*this is an automated review from Ollama*" \
|
||||||
|
'{body: $body, event: "COMMENT"}')
|
||||||
|
curl -s -X POST "http://172.0.0.29:3000/api/v1/repos/sarman/tftsr-devops_investigation/pulls/$PR_NUMBER/reviews" \
|
||||||
|
-H "Authorization: token $TF_TOKEN" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d "$BODY"
|
||||||
else
|
else
|
||||||
echo "No review to post"
|
echo "No review to post"
|
||||||
fi
|
fi
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user