name: PR Review Automation on: pull_request: types: [opened, synchronize, reopened] jobs: review: runs-on: ubuntu-latest container: image: ubuntu:22.04 steps: - name: Install dependencies run: | set -eux apt-get update -qq && apt-get install -y -qq git curl jq - name: Checkout code run: | git init git remote add origin http://172.0.0.29:3000/sarman/tftsr-devops_investigation.git git fetch --depth=1 origin ${{ github.head_ref }} git checkout FETCH_HEAD - name: Get PR diff id: diff run: | git fetch origin ${{ github.base_ref }} git diff origin/${{ github.base_ref }}..HEAD > /tmp/pr_diff.txt echo "diff_size=$(wc -l < /tmp/pr_diff.txt)" >> $GITHUB_OUTPUT - name: Analyze with Ollama if: steps.diff.outputs.diff_size > '0' env: OLLAMA_URL: http://172.0.0.29:3000/ollama/v1 API_KEY: ${{ secrets.OLLAMA_API_KEY }} run: | 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." 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}") echo "Response: $RESPONSE" > /tmp/ollama_response.txt echo "$RESPONSE" > /tmp/ollama_response.json echo "Response saved to /tmp/ollama_response.json" if [ -z "$RESPONSE" ]; then echo "ERROR: Empty response from Ollama" exit 1 fi REVIEW=$(echo "$RESPONSE" | jq -r '.choices[0].message.content // empty' 2>/dev/null || echo "Failed to parse jq response") echo "$REVIEW" > /tmp/pr_review.txt if [ -z "$REVIEW" ]; then echo "WARNING: No review content extracted" fi - name: Post review comment if: success() env: TF_TOKEN: ${{ secrets.TFT_GITEA_TOKEN }} PR_NUMBER: ${{ github.event.pull_request.number }} run: | if [ -f "/tmp/pr_review.txt" ] && [ -s "/tmp/pr_review.txt" ]; then REVIEW_BODY=$(cat /tmp/pr_review.txt | head -c 65536) 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\"}" else echo "No review to post" fi