From 2ba03b2601cbdcac53368a9710eeb91a60691d42 Mon Sep 17 00:00:00 2001 From: LiteObject Date: Thu, 22 May 2025 11:13:56 -0500 Subject: [PATCH 1/2] Update greeting message in InfoController's Get method for clarity --- .github/workflows/code-review.yml | 61 +++++++------------ .../Controllers/WeatherForecastController.cs | 2 +- 2 files changed, 24 insertions(+), 39 deletions(-) diff --git a/.github/workflows/code-review.yml b/.github/workflows/code-review.yml index 770b995..2e5d508 100644 --- a/.github/workflows/code-review.yml +++ b/.github/workflows/code-review.yml @@ -19,13 +19,7 @@ jobs: - name: Checkout Repository uses: actions/checkout@v4 with: - # Checks out the code from the pull request's head branch, the feature branch with changes. - # ref: ${{ github.event.pull_request.head.ref }} - fetch-depth: 0 - - # - name: Fetch Base Branch - # run: | - # git fetch origin ${{ github.base_ref }} + fetch-depth: 0 # Fetches all history for the entire branch - name: Generate Diff id: generate-diff @@ -44,48 +38,24 @@ jobs: with: name: sanitized-pr-diff path: sanitized_diff.txt - - # Step 6: Install Ollama + - name: Install Ollama run: | curl -fsSL https://ollama.com/install.sh | sh ollama --version - # Step 7: Pull the specified model - name: Pull Model run: | ollama pull ${{ env.MODEL_NAME }} || { echo "Failed to pull model"; exit 1; } ollama list - # Step 8: Read the diff file and prepare the prompt for Ollama - # - name: Prepare Prompt - # run: | - # DIFF=$(cat sanitized_diff.txt) - # PROMPT=$(echo "Please review the following code changes and provide feedback:\n\n$DIFF\n\nFeedback:" | sed 's/"/\\"/g') - # echo "prompt<> $GITHUB_ENV - # echo "$PROMPT" >> $GITHUB_ENV - # echo "EOF" >> $GITHUB_ENV - # shell: /usr/bin/bash -e {0} - - name: Prepare Prompt run: | DIFF=$(cat sanitized_diff.txt) - PROMPT=$(echo "Please review the following code changes and provide feedback:\n\n$DIFF\n\nFeedback:" | jq -sR .) + PROMPT=$(echo "Please review the following code changes, summarize the changes, and provide feedback:\n\n$DIFF\n\nFeedback:" | jq -sR .) echo "prompt=$PROMPT" >> $GITHUB_ENV shell: /usr/bin/bash -e {0} - # Step 9: Perform code review using Ollama - # - name: Code Review - # run: | - # RAW_RESPONSE=$(curl -s -X POST http://localhost:11434/api/generate \ - # -d '{ - # "model": "'"${{ env.MODEL_NAME }}"'", - # "prompt": "'"${{ env.prompt }}"'", - # "temperature": 0.5, - # "stream": false - # }' || { echo "API call failed"; exit 1; }) - # echo "RAW RESPONSE:\n$RAW_RESPONSE" - - name: Code Review run: | PAYLOAD=$(jq -n \ @@ -101,8 +71,23 @@ jobs: -d "$PAYLOAD" || { echo "API call failed"; exit 1; }) echo "RAW RESPONSE:\n$RAW_RESPONSE" - # Step 9: Optionally save the response as an artifact - # - name: Save Response as Artifact - # run: | - # echo "$RAW_RESPONSE" > response.json - # if: always() \ No newline at end of file + # Try to extract the response, fallback to a default message if not found + REVIEW=$(echo "$RAW_RESPONSE" | jq -r '.response') + + if [ -z "$REVIEW" ]; then + echo "Model did not return a valid review. Check RAW_RESPONSE for errors." + 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; + await github.rest.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.issue.number, + body: `### AI Review\n\n${review}` + }); \ No newline at end of file diff --git a/src/MyWebApi/MyWebApi/Controllers/WeatherForecastController.cs b/src/MyWebApi/MyWebApi/Controllers/WeatherForecastController.cs index d589b81..1ac078a 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 hello = "Hello"; + var hello = "Hello World"; // Log a message at the Information level var message = "Hello World from InfoController. This is a sample message."; _logger.LogInformation(message); From 0b18a1c8ce991c8b9b798f4c6683f6bd21eff735 Mon Sep 17 00:00:00 2001 From: LiteObject Date: Thu, 22 May 2025 14:22:46 -0500 Subject: [PATCH 2/2] Update diff generation command to increase context lines for better clarity --- .github/workflows/code-review.yml | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/.github/workflows/code-review.yml b/.github/workflows/code-review.yml index 2e5d508..7960906 100644 --- a/.github/workflows/code-review.yml +++ b/.github/workflows/code-review.yml @@ -25,8 +25,14 @@ jobs: id: generate-diff run: | echo "Generating diff between ${{ github.base_ref }} and ${{ github.head_ref }}" - # git diff --unified=5 origin/${{ github.base_ref }}...${{ github.head_ref }} > changes.diff - git diff --unified=0 origin/${{ github.event.pull_request.base.ref }}..${{ github.event.pull_request.head.ref }} > changes.diff + git diff --unified=5 origin/${{ github.base_ref }}...${{ github.head_ref }} > changes.diff + # git diff --unified=0 origin/${{ github.event.pull_request.base.ref }}..${{ github.event.pull_request.head.ref }} > changes.diff + + # - name: Generate Diff + # id: generate-diff + # run: | + # echo "Generating diff between ${{ github.base_ref }} and pull request head" + # git diff --unified=0 origin/${{ github.event.pull_request.base.ref }}..FETCH_HEAD > changes.diff - name: Sanitize Diff run: |