Skip to content

Commit de28e76

Browse files
authored
Merge pull request #32 from truongnh1992/improve-prompt
Test new prompt
2 parents 9408edb + 052ff94 commit de28e76

File tree

3 files changed

+11
-12
lines changed

3 files changed

+11
-12
lines changed

Demo.png

911 Bytes
Loading

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
runs-on: ubuntu-latest
3434
steps:
3535
- name: Checkout Repo
36-
uses: actions/checkout@v4
36+
uses: actions/checkout@v3
3737

3838
- name: Run Gemini AI Code Reviewer
3939
uses: truongnh1992/gemini-ai-code-reviewer@latest
@@ -43,8 +43,9 @@ jobs:
4343
INPUT_EXCLUDE: "*.md,*.txt,package-lock.json,*.yml,*.yaml" # Optional: exclude patterns separated by commas
4444
```
4545
46-
4. Commit codes to your repository, and `Gemini AI Code Reviewer` will start working on your pull requests.
47-
46+
4. Commit codes to your repository, and working on your pull requests.
47+
5. When you're ready to review the PR, you can trigger the workflow by commenting `/gemini-review` in the PR.
48+
4849
## How It Works
4950

5051
This GitHub Action uses the Gemini AI API to provide code review feedback. It works by:

review_code_gemini.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,10 @@ def create_prompt(file: PatchedFile, hunk: Hunk, pr_details: PRDetails) -> str:
135135
"""Creates the prompt for the Gemini model."""
136136
return f"""Your task is reviewing pull requests. Instructions:
137137
- Provide the response in following JSON format: {{"reviews": [{{"lineNumber": <line_number>, "reviewComment": "<review comment>"}}]}}
138-
- Do not give positive comments or compliments.
139138
- Provide comments and suggestions ONLY if there is something to improve, otherwise "reviews" should be an empty array.
140-
- Write the comment in GitHub Markdown format.
141-
- Use the given description only for the overall context and only comment the code.
142-
- IMPORTANT: NEVER suggest adding comments to the code.
139+
- Use GitHub Markdown in comments
140+
- Focus on bugs, security issues, and performance problems
141+
- IMPORTANT: NEVER suggest adding comments to the code
143142
144143
Review the following code diff in the file "{file.path}" and take the pull request title and description into account when writing the response.
145144
@@ -216,15 +215,14 @@ def create_comment(file: FileInfo, hunk: Hunk, ai_responses: List[Dict[str, str]
216215
line_number = int(ai_response["lineNumber"])
217216
print(f"Original AI suggested line: {line_number}")
218217

219-
# Ensure the line number is within the hunk's range
220-
if line_number < 1 or line_number > hunk.source_length:
221-
print(f"Warning: Line number {line_number} is outside hunk range")
222-
continue
218+
# Adjust line number to be relative to the hunk's starting position
219+
adjusted_line_number = hunk.source_start + line_number - 1
220+
print(f"Adjusted line number: {adjusted_line_number}")
223221

224222
comment = {
225223
"body": ai_response["reviewComment"],
226224
"path": file.path,
227-
"position": line_number
225+
"position": adjusted_line_number
228226
}
229227
print(f"Created comment: {json.dumps(comment, indent=2)}")
230228
comments.append(comment)

0 commit comments

Comments
 (0)