Skip to content

Update greeting message in InfoController's Get method for clarity #40

Update greeting message in InfoController's Get method for clarity

Update greeting message in InfoController's Get method for clarity #40

Workflow file for this run

name: PR Code Review with AI
# Trigger the workflow when a pull request is opened or updated
on:
pull_request_target:
branches:
- main
jobs:
code-review:
name: Review Changes with AI
runs-on: ubuntu-latest
permissions:
issues: write # Allows the workflow to write comments on issues and pull requests
pull-requests: write # Allows the workflow to write comments on pull requests
env:
MODEL_NAME: "llama3.2:latest"
steps:
- name: Checkout Repository
uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetches all history for the entire branch
- name: Fetch all branches
run: git fetch --all
- name: Generate Diff
id: generate-diff
run: |
echo "Generating diff between origin/${{ github.base_ref }} and origin/${{ github.head_ref }}"
git diff --unified=5 origin/${{ github.base_ref }}...origin/${{ github.head_ref }} > changes.diff
- name: Sanitize Diff
run: |
# Remove metadata lines and retain only actual code changes (+/-)
grep -E '^(\+|-)' changes.diff | sed 's/^+/Added: /; s/^-/Removed: /' > sanitized_diff.txt
- name: Upload Diff as Artifact
uses: actions/upload-artifact@v4
with:
name: sanitized-pr-diff
path: sanitized_diff.txt
- name: Install Ollama
run: |
curl -fsSL https://ollama.com/install.sh | sh
ollama --version
- name: Pull Model
run: |
ollama pull ${{ env.MODEL_NAME }} || { echo "Failed to pull model"; exit 1; }
ollama list
- name: Prepare Prompt
run: |
DIFF=$(cat sanitized_diff.txt)
PROMPT=$(echo "Please review the following code changes, summarize the changes, and provide feedback:\n\n$DIFF\n\nFeedback:" | jq -sR .)
echo "PROMPT:\n$PROMPT"
# Set the prompt as an environment variable for later steps
echo "prompt=$PROMPT" >> $GITHUB_ENV
shell: /usr/bin/bash -e {0}
- name: Code Review
run: |
PAYLOAD=$(jq -n \
--arg model "$MODEL_NAME" \
--arg prompt "$PROMPT" \
'{
model: $model,
prompt: $prompt,
temperature: 0.5,
stream: false
}')
RAW_RESPONSE=$(curl -s -X POST http://localhost:11434/api/generate \
-d "$PAYLOAD" || { echo "API call failed"; exit 1; })
echo "RAW RESPONSE:\n$RAW_RESPONSE"
# Try to extract the response, fallback to a default message if not found
REVIEW=$(echo "$RAW_RESPONSE" | jq -r '.response // empty')
if [ -z "$REVIEW" ] || [ "$REVIEW" = "null" ]; then
echo "Error: .response field is missing or empty in the API response."
REVIEW="Model did not return a valid review. RAW_RESPONSE: $RAW_RESPONSE"
fi
- name: Post Review Comment
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const review = process.env.REVIEW || 'No review generated due to an error.';
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: `### AI Review\n\n${review}`
});