Skip to content

Commit a97b943

Browse files
committed
Enhance diff generation by increasing context lines and update prompt preparation to use jq for better formatting
1 parent 5dc9f02 commit a97b943

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

.github/workflows/code-review.yml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232
id: generate-diff
3333
run: |
3434
echo "Generating diff between ${{ github.base_ref }} and ${{ github.head_ref }}"
35-
git diff origin/${{ github.base_ref }}...${{ github.head_ref }} > changes.diff
35+
git diff --unified=5 origin/${{ github.base_ref }}...${{ github.head_ref }} > changes.diff
3636
3737
# Step 4: Sanitize the diff file
3838
- name: Sanitize Diff
@@ -41,43 +41,43 @@ jobs:
4141
grep -E '^(\+|-)' changes.diff | sed 's/^+/Added: /; s/^-/Removed: /' > sanitized_diff.txt
4242
4343

44-
# Step 4: Upload the diff file as an artifact (optional)
44+
# Step 5: Upload the diff file as an artifact (optional)
4545
- name: Upload Diff as Artifact
4646
uses: actions/upload-artifact@v4
4747
with:
4848
name: sanitized-pr-diff
4949
path: sanitized_diff.txt
5050

51-
# Step 5: Install Ollama
51+
# Step 6: Install Ollama
5252
- name: Install Ollama
5353
run: |
5454
curl -fsSL https://ollama.com/install.sh | sh
5555
ollama --version
5656
57-
# Step 6: Pull the specified model
57+
# Step 7: Pull the specified model
5858
- name: Pull Model
5959
run: |
6060
ollama pull ${{ env.MODEL_NAME }} || { echo "Failed to pull model"; exit 1; }
6161
ollama list
6262
63-
# Step 7: Read the diff file and prepare the prompt for Ollama
63+
# Step 8: Read the diff file and prepare the prompt for Ollama
6464
# - name: Prepare Prompt
65-
# id: prepare-prompt
6665
# run: |
6766
# DIFF=$(cat sanitized_diff.txt)
6867
# PROMPT=$(echo "Please review the following code changes and provide feedback:\n\n$DIFF\n\nFeedback:" | sed 's/"/\\"/g')
69-
# echo "prompt=$PROMPT" >> $GITHUB_ENV
68+
# echo "prompt<<EOF" >> $GITHUB_ENV
69+
# echo "$PROMPT" >> $GITHUB_ENV
70+
# echo "EOF" >> $GITHUB_ENV
71+
# shell: /usr/bin/bash -e {0}
7072

7173
- name: Prepare Prompt
7274
run: |
7375
DIFF=$(cat sanitized_diff.txt)
74-
PROMPT=$(echo "Please review the following code changes and provide feedback:\n\n$DIFF\n\nFeedback:" | sed 's/"/\\"/g')
75-
echo "prompt<<EOF" >> $GITHUB_ENV
76-
echo "$PROMPT" >> $GITHUB_ENV
77-
echo "EOF" >> $GITHUB_ENV
76+
PROMPT=$(echo "Please review the following code changes and provide feedback:\n\n$DIFF\n\nFeedback:" | jq -sR .)
77+
echo "prompt=$PROMPT" >> $GITHUB_ENV
7878
shell: /usr/bin/bash -e {0}
7979

80-
# Step 8: Perform code review using Ollama
80+
# Step 9: Perform code review using Ollama
8181
- name: Code Review
8282
run: |
8383
RAW_RESPONSE=$(curl -s -X POST http://localhost:11434/api/generate \

0 commit comments

Comments
 (0)