Skip to content

Commit ae605e3

Browse files
authored
Merge pull request #6 from LiteObject/feature/refactor_code
Refactor logging in InfoController's Get method for improved readability
2 parents 13b5628 + 90c8444 commit ae605e3

File tree

2 files changed

+40
-24
lines changed

2 files changed

+40
-24
lines changed

.github/workflows/code-review.yml

+38-22
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: PR Code Review with Ollama
1+
name: PR Code Review with LLM
22

33
# Trigger the workflow when a pull request is opened or updated
44
on:
@@ -14,58 +14,74 @@ jobs:
1414
env:
1515
MODEL_NAME: "llama3.2:latest"
1616
steps:
17-
# Checkout the repository code
17+
# Step 1: Checkout the repository code
1818
- name: Checkout Repository
1919
uses: actions/checkout@v4
2020
with:
2121
# Checks out the code from the pull request's head branch.
2222
ref: ${{ github.event.pull_request.head.ref }}
2323
fetch-depth: 0
24-
25-
# Fetches the base branch (e.g., main) from the remote repository
24+
25+
# Step 2: Fetch the base branch (e.g., main) from the remote repository
2626
- name: Fetch Base Branch
2727
run: |
2828
git fetch origin ${{ github.base_ref }}
2929
30-
# - name: Fetch Pull Request Branch
31-
# run: git fetch origin pull/${{ github.event.pull_request.number }}/head:pr-branch
32-
30+
# Step 3: Generate the diff between the base branch and the PR branch
3331
- name: Generate Diff
34-
id: generate-diff
32+
id: generate-diff
3533
run: |
3634
echo "Generating diff between ${{ github.base_ref }} and ${{ github.head_ref }}"
37-
DIFF=$(git diff origin/${{ github.base_ref }}...${{ github.head_ref }})
38-
echo "diff_output=$DIFF" >> $GITHUB_ENV
39-
40-
# Step 4: Output the diff (optional)
41-
- name: Print Diff
42-
run: |
43-
echo "Diff Output:"
44-
echo "${{ env.diff_output }}"
35+
git diff origin/${{ github.base_ref }}...${{ github.head_ref }} > changes.diff
4536
46-
# Step 5: Save the diff to a file (optional)
47-
- name: Save diff to file
48-
run: |
49-
echo "${{ env.diff_output }}" > changes.diff
37+
# Step 4: Upload the diff file as an artifact (optional)
38+
- name: Upload Diff as Artifact
39+
uses: actions/upload-artifact@v3
40+
with:
41+
name: pr-diff
42+
path: changes.diff
5043

44+
# Step 5: Install Ollama
5145
- name: Install Ollama
5246
run: |
5347
curl -fsSL https://ollama.com/install.sh | sh
5448
ollama --version
5549
50+
# Step 6: Pull the specified model
5651
- name: Pull Model
5752
run: |
5853
ollama pull ${{ env.MODEL_NAME }} || { echo "Failed to pull model"; exit 1; }
5954
ollama list
6055
56+
# Step 7: Read the diff file and prepare the prompt for Ollama
57+
- name: Prepare Prompt
58+
id: prepare-prompt
59+
run: |
60+
DIFF=$(cat changes.diff)
61+
PROMPT=$(echo "Please review the following code changes and provide feedback:\n\n$DIFF\n\nFeedback:" | sed 's/"/\\"/g')
62+
echo "prompt=$PROMPT" >> $GITHUB_ENV
63+
64+
# Step 8: Perform code review using Ollama
6165
- name: Code Review
6266
run: |
63-
prompt=$(echo "Please review the following code changes and provide feedback:\n\n${{ env.diff_output }}\n\nFeedback:" | sed 's/"/\\"/g')
6467
RAW_RESPONSE=$(curl -s -X POST http://localhost:11434/api/generate \
6568
-d '{
6669
"model": "'"${{ env.MODEL_NAME }}"'",
67-
"prompt": "'"${prompt}"'",
70+
"prompt": "'"${{ env.prompt }}"'",
6871
"temperature": 0.5,
6972
"stream": false
7073
}' || { echo "API call failed"; exit 1; })
7174
echo "RAW RESPONSE:\n$RAW_RESPONSE"
75+
76+
# Step 9: Optionally save the response as an artifact
77+
- name: Save Response as Artifact
78+
run: |
79+
echo "$RAW_RESPONSE" > response.json
80+
if: always()
81+
82+
- name: Upload Response as Artifact
83+
uses: actions/upload-artifact@v3
84+
with:
85+
name: ollama-response
86+
path: response.json
87+
if: always()

src/MyWebApi/MyWebApi/Controllers/WeatherForecastController.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ public IActionResult Get()
1818
{
1919
// Log a message at the Information level
2020
var message = "Hello World from InfoController!";
21-
_logger.LogInformation("Hello World from InfoController!");
22-
return Ok("Hello World");
21+
_logger.LogInformation(message);
22+
return Ok(message);
2323
}
2424
}
2525
}

0 commit comments

Comments
 (0)