Skip to content

Update greeting message in InfoController's Get method for consistency #48

Update greeting message in InfoController's Get method for consistency

Update greeting message in InfoController's Get method for consistency #48

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=10 origin/${{ github.base_ref }}...origin/${{ github.head_ref }} > changes.diff
# Check if diff is empty
if [ ! -s changes.diff ]; then
echo "No changes detected"
echo "NO_CHANGES=true" >> $GITHUB_ENV
exit 0
fi
# Limit diff size to avoid token limits (first 100 lines)
head -100 changes.diff > limited_changes.diff
mv limited_changes.diff 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
echo "Sanitized diff content:"
cat 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
# Verify model is available via API
echo "Verifying model availability via API..."
curl -s http://localhost:11434/api/tags | jq '.'
- name: Wait for Ollama to be ready
run: |
for i in {1..10}; do
if curl -s http://localhost:11434/api/tags | jq '.'; then
echo "Ollama is ready."
break
fi
echo "Waiting for Ollama to be ready..."
sleep 3
done
- name: Prepare Prompt
run: |
DIFF=$(cat sanitized_diff.txt)
# Check if diff is empty
if [ -z "$DIFF" ]; then
echo "No changes detected in the diff"
DIFF="No code changes detected in this pull request."
fi
PROMPT="Please review the following code changes, summarize the changes, and provide feedback:
$DIFF
Feedback:"
echo "PROMPT:"
echo "$PROMPT"
# Export PROMPT so it's available to later steps
echo "prompt<<EOF" >> $GITHUB_ENV
echo "$PROMPT" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
shell: /usr/bin/bash -e {0}
- name: Code Review
run: |
echo "Starting code review with model: $MODEL_NAME"
PAYLOAD=$(jq -n \
--arg model "$MODEL_NAME" \
--arg prompt "$PROMPT" \
'{
model: $model,
prompt: $prompt,
temperature: 0.5,
stream: false
}')
echo "Sending request to Ollama API..."
RAW_RESPONSE=$(curl -s -X POST http://localhost:11434/api/generate \
-H "Content-Type: application/json" \
-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
echo "Final review content:"
echo "$REVIEW"
# Export REVIEW for the next step
echo "review<<EOF" >> $GITHUB_ENV
echo "$REVIEW" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
- 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}`
});