diff --git a/.github/workflows/code-review.yml b/.github/workflows/code-review.yml index a613a75..7b4257a 100644 --- a/.github/workflows/code-review.yml +++ b/.github/workflows/code-review.yml @@ -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 @@ -51,9 +53,19 @@ 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: @@ -61,10 +73,8 @@ jobs: 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<> $GITHUB_ENV @@ -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" \ @@ -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 @@ -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<> $GITHUB_ENV + echo "$REVIEW" >> $GITHUB_ENV + echo "EOF" >> $GITHUB_ENV + - name: Post Review Comment uses: actions/github-script@v6 with: diff --git a/src/MyWebApi/MyWebApi/Controllers/WeatherForecastController.cs b/src/MyWebApi/MyWebApi/Controllers/WeatherForecastController.cs index f6f7881..072af81 100644 --- a/src/MyWebApi/MyWebApi/Controllers/WeatherForecastController.cs +++ b/src/MyWebApi/MyWebApi/Controllers/WeatherForecastController.cs @@ -16,7 +16,7 @@ public InfoController(ILogger 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);