Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 29 additions & 5 deletions .github/workflows/code-review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@ jobs:
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
git diff --unified=10 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
echo "Sanitized diff content:"
cat sanitized_diff.txt

- name: Upload Diff as Artifact
uses: actions/upload-artifact@v4
Expand All @@ -51,20 +53,28 @@ jobs:
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: 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:\n$PROMPT"

# Set the prompt as an environment variable for later steps
# echo "prompt=$PROMPT" >> $GITHUB_ENV
echo "PROMPT:"
echo "$PROMPT"

# Export PROMPT so it's available to later steps
echo "prompt<<EOF" >> $GITHUB_ENV
Expand All @@ -75,6 +85,8 @@ jobs:

- name: Code Review
run: |
echo "Starting code review with model: $MODEL_NAME"

PAYLOAD=$(jq -n \
--arg model "$MODEL_NAME" \
--arg prompt "$PROMPT" \
Expand All @@ -84,8 +96,12 @@ jobs:
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
Expand All @@ -96,6 +112,14 @@ jobs:
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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public InfoController(ILogger<InfoController> logger)
[HttpGet(Name = "Get")]
public IActionResult Get()
{
var helloworld = "Hello World from InfoController";
var _helloworld = "Hello World from InfoController!!!";
var message = "Hello World from InfoController. This is a sample message.";
_logger.LogInformation(message);
return Ok(message);
Expand Down