Skip to content

Pull request trigger #6

Pull request trigger

Pull request trigger #6

Workflow file for this run

name: PR Code Review with LLM
on:
pull_request:
types: [opened, synchronize]
jobs:
code-review:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@v34
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Extract changed files content
run: |
echo "" > code_changes.txt
IFS=',' read -r -a files <<< "${{ steps.changed-files.outputs.all_changed_files }}"
for file in "${files[@]}"; do
echo "--- FILE: $file ---" >> code_changes.txt
cat "$file" >> code_changes.txt || echo "[File not found: $file]" >> code_changes.txt
done
- name: Debug input to API
run: |
echo "Input to API:"
cat code_changes.txt
- name: Escape code changes
run: |
escaped_content=$(cat code_changes.txt | jq -Rsa '.')
echo "escaped_content=$escaped_content" >> $GITHUB_ENV
- name: Send to LLM API
id: call-llm
run: |
curl -X POST https://solana-chat-60707405365.us-central1.run.app \
-H "Content-Type: application/json" \
-d "{
\"question\": \"You are an expert pull request reviewer. Search for similar code and analyze the following code changes for inefficiencies, missing documentation, and insecurities. Here is the code: print(hello world)\"
}" > llm_response.json
- name: Debug API response
run: |
echo "Raw API response:"
cat llm_response.json
- name: Parse API response
id: parse-response
run: |
# Extract the first element of the 'parts' array from the response JSON
response=$(jq -r '.answer.parts[0].text' llm_response.json)
echo "response=$response" >> $GITHUB_ENV
- name: Create PR comment
uses: marocchino/sticky-pull-request-comment@v2
with:
token: ${{ secrets.GITHUB_TOKEN }}
header: "AI Code Review"
message: |
### AI Analysis
${{ env.response }}