diff --git a/.github/workflows/code-review.yml b/.github/workflows/code-review.yml index 770b995..7960906 100644 --- a/.github/workflows/code-review.yml +++ b/.github/workflows/code-review.yml @@ -19,20 +19,20 @@ 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 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: | @@ -44,48 +44,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 +77,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);