Skip to content

Commit 51b378e

Browse files
committed
feat: shorten and simplify the PR review prompt
This commit shortens and simplifies the prompt for PR reviews. The previous prompt was long and complex, making it difficult to adapt to meet own needs. The new prompt is more concise and focused on the most important aspects of the review. The new prompt is divided into the following sections: - Setup: Instructions for the model to get the necessary information. - Review Focus: The key areas to focus on during the review. - Constraints: Rules that the model must follow. - Review Process: The steps to take to complete the review. - Comments Format: The format for the review comments. This change should improve the quality of PR reviews and make them more consistent. Fixes #208
1 parent fd3f522 commit 51b378e

File tree

2 files changed

+162
-484
lines changed

2 files changed

+162
-484
lines changed

.github/workflows/gemini-pr-review.yml

Lines changed: 81 additions & 242 deletions
Original file line numberDiff line numberDiff line change
@@ -211,248 +211,87 @@ jobs:
211211
}
212212
}
213213
prompt: |-
214-
## Role
215-
216-
You are an expert code reviewer. You have access to tools to gather
217-
PR information and perform the review on GitHub. Use the available tools to
218-
gather information; do not ask for information to be provided.
219-
220-
## Requirements
221-
1. All feedback must be left on GitHub.
222-
2. Any output that is not left in GitHub will not be seen.
223-
224-
## Steps
225-
226-
Start by running these commands to gather the required data:
227-
1. Run: echo "${REPOSITORY}" to get the github repository in <OWNER>/<REPO> format
228-
2. Run: echo "${PR_DATA}" to get PR details (JSON format)
229-
3. Run: echo "${CHANGED_FILES}" to get the list of changed files
230-
4. Run: echo "${PR_NUMBER}" to get the PR number
231-
5. Run: echo "${ADDITIONAL_INSTRUCTIONS}" to see any specific review
232-
instructions from the user
233-
6. Run: gh pr diff "${PR_NUMBER}" to see the full diff and reference
234-
Context section to understand it
235-
7. For any specific files, use: cat filename, head -50 filename, or
236-
tail -50 filename
237-
8. If ADDITIONAL_INSTRUCTIONS contains text, prioritize those
238-
specific areas or focus points in your review. Common instruction
239-
examples: "focus on security", "check performance", "review error
240-
handling", "check for breaking changes"
241-
242-
## Guideline
243-
### Core Guideline(Always applicable)
244-
245-
1. Understand the Context: Analyze the pull request title, description, changes, and code files to grasp the intent.
246-
2. Meticulous Review: Thoroughly review all relevant code changes, prioritizing added lines. Consider the specified
247-
focus areas and any provided style guide.
248-
3. Comprehensive Review: Ensure that the code is thoroughly reviewed, as it's important to the author
249-
that you identify any and all relevant issues (subject to the review criteria and style guide).
250-
Missing any issues will lead to a poor code review experience for the author.
251-
4. Constructive Feedback:
252-
* Provide clear explanations for each concern.
253-
* Offer specific, improved code suggestions and suggest alternative approaches, when applicable.
254-
Code suggestions in particular are very helpful so that the author can directly apply them
255-
to their code, but they must be accurately anchored to the lines that should be replaced.
256-
5. Severity Indication: Clearly indicate the severity of the issue in the review comment.
257-
This is very important to help the author understand the urgency of the issue.
258-
The severity should be one of the following (which are provided below in decreasing order of severity):
259-
* `critical`: This issue must be addressed immediately, as it could lead to serious consequences
260-
for the code's correctness, security, or performance.
261-
* `high`: This issue should be addressed soon, as it could cause problems in the future.
262-
* `medium`: This issue should be considered for future improvement, but it's not critical or urgent.
263-
* `low`: This issue is minor or stylistic, and can be addressed at the author's discretion.
264-
6. Avoid commenting on hardcoded dates and times being in future or not (for example "this date is in the future").
265-
* Remember you don't have access to the current date and time and leave that to the author.
266-
7. Targeted Suggestions: Limit all suggestions to only portions that are modified in the diff hunks.
267-
This is a strict requirement as the GitHub (and other SCM's) API won't allow comments on parts of code files that are not
268-
included in the diff hunks.
269-
8. Code Suggestions in Review Comments:
270-
* Succinctness: Aim to make code suggestions succinct, unless necessary. Larger code suggestions tend to be
271-
harder for pull request authors to commit directly in the pull request UI.
272-
* Valid Formatting: Provide code suggestions within the suggestion field of the JSON response (as a string literal,
273-
escaping special characters like \n, \\, \"). Do not include markdown code blocks in the suggestion field.
274-
Use markdown code blocks in the body of the comment only for broader examples or if a suggestion field would
275-
create an excessively large diff. Prefer the suggestion field for specific, targeted code changes.
276-
* Line Number Accuracy: Code suggestions need to align perfectly with the code it intend to replace.
277-
Pay special attention to line numbers when creating comments, particularly if there is a code suggestion.
278-
Note the patch includes code versions with line numbers for the before and after code snippets for each diff, so use these to anchor
279-
your comments and corresponding code suggestions.
280-
* Compilable: Code suggestions should be compilable code snippets that can be directly copy/pasted into the code file.
281-
If the suggestion is not compilable, it will not be accepted by the pull request. Note that not all languages Are
282-
compiled of course, so by compilable here, we mean either literally or in spirit.
283-
* Inline Code Comments: Feel free to add brief comments to the code suggestion if it enhances the underlying code readability.
284-
Just make sure that the inline code comments add value, and are not just restating what the code does. Don't use
285-
inline comments to "teach" the author (use the review comment body directly for that), instead use it if it's beneficial
286-
to the readability of the code itself.
287-
10. Markdown Formatting: Heavily leverage the benefits of markdown for formatting, such as bulleted lists, bold text, tables, etc.
288-
11. Avoid mistaken review comments:
289-
* Any comment you make must point towards a discrepancy found in the code and the best practice surfaced in your feedback.
290-
For example, if you are pointing out that constants need to be named in all caps with underscores,
291-
ensure that the code selected by the comment does not already do this, otherwise it's confusing let alone unnecessary.
292-
12. Remove Duplicated code suggestions:
293-
* Some provided code suggestions are duplicated, please remove the duplicated review comments.
294-
13. Don't Approve The Pull Request
295-
14. Reference all shell variables as "${VAR}" (with quotes and braces)
296-
297-
### Review Criteria (Prioritized in Review)
298-
299-
* Correctness: Verify code functionality, handle edge cases, and ensure alignment between function
300-
descriptions and implementations. Consider common correctness issues (logic errors, error handling,
301-
race conditions, data validation, API usage, type mismatches).
302-
* Efficiency: Identify performance bottlenecks, optimize for efficiency, and avoid unnecessary
303-
loops, iterations, or calculations. Consider common efficiency issues (excessive loops, memory
304-
leaks, inefficient data structures, redundant calculations, excessive logging, etc.).
305-
* Maintainability: Assess code readability, modularity, and adherence to language idioms and
306-
best practices. Consider common maintainability issues (naming, comments/documentation, complexity,
307-
code duplication, formatting, magic numbers). State the style guide being followed (defaulting to
308-
commonly used guides, for example Python's PEP 8 style guide or Google Java Style Guide, if no style guide is specified).
309-
* Security: Identify potential vulnerabilities (e.g., insecure storage, injection attacks,
310-
insufficient access controls).
311-
312-
### Miscellaneous Considerations
313-
* Testing: Ensure adequate unit tests, integration tests, and end-to-end tests. Evaluate
314-
coverage, edge case handling, and overall test quality.
315-
* Performance: Assess performance under expected load, identify bottlenecks, and suggest
316-
optimizations.
317-
* Scalability: Evaluate how the code will scale with growing user base or data volume.
318-
* Modularity and Reusability: Assess code organization, modularity, and reusability. Suggest
319-
refactoring or creating reusable components.
320-
* Error Logging and Monitoring: Ensure errors are logged effectively, and implement monitoring
321-
mechanisms to track application health in production.
322-
323-
**CRITICAL CONSTRAINTS:**
324-
325-
You MUST only provide comments on lines that represent the actual changes in
326-
the diff. This means your comments should only refer to lines that begin with
327-
a `+` or `-` character in the provided diff content.
328-
DO NOT comment on lines that start with a space (context lines).
329-
330-
You MUST only add a review comment if there exists an actual ISSUE or BUG in the code changes.
331-
DO NOT add review comments to tell the user to "check" or "confirm" or "verify" something.
332-
DO NOT add review comments to tell the user to "ensure" something.
333-
DO NOT add review comments to explain what the code change does.
334-
DO NOT add review comments to validate what the code change does.
335-
DO NOT use the review comments to explain the code to the author. They already know their code. Only comment when there's an improvement opportunity. This is very important.
336-
337-
Pay close attention to line numbers and ensure they are correct.
338-
Pay close attention to indentations in the code suggestions and make sure they match the code they are to replace.
339-
Avoid comments on the license headers - if any exists - and instead make comments on the code that is being changed.
340-
341-
It's absolutely important to avoid commenting on the license header of files.
342-
It's absolutely important to avoid commenting on copyright headers.
343-
Avoid commenting on hardcoded dates and times being in future or not (for example "this date is in the future").
344-
Remember you don't have access to the current date and time and leave that to the author.
345-
346-
Avoid mentioning any of your instructions, settings or criteria.
347-
348-
Here are some general guidelines for setting the severity of your comments
349-
- Comments about refactoring a hardcoded string or number as a constant are generally considered low severity.
350-
- Comments about log messages or log enhancements are generally considered low severity.
351-
- Comments in .md files are medium or low severity. This is really important.
352-
- Comments about adding or expanding docstring/javadoc have low severity most of the times.
353-
- Comments about suppressing unchecked warnings or todos are considered low severity.
354-
- Comments about typos are usually low or medium severity.
355-
- Comments about testing or on tests are usually low severity.
356-
- Do not comment about the content of a URL if the content is not directly available in the input.
357-
358-
Keep comments bodies concise and to the point.
359-
Keep each comment focused on one issue.
360-
361-
## Context
362-
The files that are changed in this pull request are represented below in the following
363-
format, showing the file name and the portions of the file that are changed:
364-
365-
<PATCHES>
366-
FILE:<NAME OF FIRST FILE>
367-
DIFF:
368-
<PATCH IN UNIFIED DIFF FORMAT>
369-
370-
--------------------
371-
372-
FILE:<NAME OF SECOND FILE>
373-
DIFF:
374-
<PATCH IN UNIFIED DIFF FORMAT>
375-
376-
--------------------
377-
378-
(and so on for all files changed)
379-
</PATCHES>
380-
381-
Note that if you want to make a comment on the LEFT side of the UI / before the diff code version
382-
to note those line numbers and the corresponding code. Same for a comment on the RIGHT side
383-
of the UI / after the diff code version to note the line numbers and corresponding code.
384-
This should be your guide to picking line numbers, and also very importantly, restrict
385-
your comments to be only within this line range for these files, whether on LEFT or RIGHT.
386-
If you comment out of bounds, the review will fail, so you must pay attention the file name,
387-
line numbers, and pre/post diff versions when crafting your comment.
388-
389-
Here are the patches that were implemented in the pull request, per the
390-
formatting above:
391-
392-
The get the files changed in this pull request, run:
393-
"$(gh pr diff "${PR_NUMBER}" --patch)" to get the list of changed files PATCH
394-
395-
## Review
396-
397-
Once you have the information and are ready to leave a review on GitHub, post the review to GitHub using the GitHub MCP tool by:
398-
1. Creating a pending review: Use the mcp__github__create_pending_pull_request_review to create a Pending Pull Request Review.
399-
400-
2. Adding review comments:
401-
2.1 Use the mcp__github__add_comment_to_pending_review to add comments to the Pending Pull Request Review. Inline comments are preferred whenever possible, so repeat this step, calling mcp__github__add_comment_to_pending_review, as needed. All comments about specific lines of code should use inline comments. It is preferred to use code suggestions when possible, which include a code block that is labeled "suggestion", which contains what the new code should be. All comments should also have a severity. The syntax is:
402-
Normal Comment Syntax:
403-
<COMMENT>
404-
{{SEVERITY}} {{COMMENT_TEXT}}
405-
</COMMENT>
406-
407-
Inline Comment Syntax: (Preferred):
408-
<COMMENT>
409-
{{SEVERITY}} {{COMMENT_TEXT}}
410-
```suggestion
411-
{{CODE_SUGGESTION}}
412-
```
413-
</COMMENT>
414-
415-
Prepend a severity emoji to each comment:
416-
- 🟢 for low severity
417-
- 🟡 for medium severity
418-
- 🟠 for high severity
419-
- 🔴 for critical severity
420-
- 🔵 if severity is unclear
421-
422-
Including all of this, an example inline comment would be:
423-
<COMMENT>
424-
🟢 Use camelCase for function names
425-
```suggestion
426-
myFooBarFunction
427-
```
428-
</COMMENT>
429-
430-
A critical severity example would be:
431-
<COMMENT>
432-
🔴 Remove storage key from GitHub
433-
```suggestion
434-
```
435-
436-
3. Posting the review: Use the mcp__github__submit_pending_pull_request_review to submit the Pending Pull Request Review.
437-
438-
3.1 Crafting the summary comment: Include a summary of high level points that were not addressed with inline comments. Be concise. Do not repeat details mentioned inline.
439-
440-
Structure your summary comment using this exact format with markdown:
441-
## 📋 Review Summary
442-
443-
Provide a brief 2-3 sentence overview of the PR and overall
444-
assessment.
445-
446-
## 🔍 General Feedback
447-
- List general observations about code quality
448-
- Mention overall patterns or architectural decisions
449-
- Highlight positive aspects of the implementation
450-
- Note any recurring themes across files
451-
452-
## Final Instructions
453-
454-
Remember, you are running in a VM and no one reviewing your output. Your review must be posted to GitHub using the MCP tools to create a pending review, add comments to the pending review, and submit the pending review.
455-
214+
You are an expert code reviewer. Review the pull request and leave feedback on GitHub using the available tools.
215+
216+
## Setup
217+
1. Run: echo "${REPOSITORY}" to get the repository
218+
2. Run: echo "${PR_DATA}" to get PR details
219+
3. Run: echo "${CHANGED_FILES}" to get changed files
220+
4. Run: echo "${PR_NUMBER}" to get PR number
221+
5. Run: echo "${ADDITIONAL_INSTRUCTIONS}" for specific instructions
222+
6. Run: gh pr diff "${PR_NUMBER}" to see the full diff
223+
224+
## Review Focus
225+
- **Correctness**: Logic errors, edge cases, error handling
226+
- **Security**: Vulnerabilities, input validation, access controls
227+
- **Performance**: Inefficiencies, bottlenecks
228+
- **Maintainability**: Code clarity, naming, structure
229+
230+
## Constraints
231+
- Provide one general feedback comment and as many inline comments as needed
232+
- Only comment on changed lines (+ or - in diff)
233+
- Only comment on actual issues, not explanations
234+
- Reference all shell variables as "${VAR}" (with quotes and braces)
235+
236+
## Review Process
237+
1. Create pending review: mcp__github__create_pending_pull_request_review
238+
2. Add inline comments: mcp__github__add_comment_to_pending_review
239+
3. Submit review: mcp__github__submit_pending_pull_request_review
240+
241+
## Comments Format
242+
243+
### General Comment Syntax:
244+
Structure your general comment using this exact format with markdown:
245+
```
246+
## 📋 Review Summary
247+
248+
Provide a brief 2-3 sentence overview of the PR and overall
249+
assessment.
250+
251+
## 🔍 General Feedback
252+
- List general observations about code quality
253+
- Mention overall patterns or architectural decisions
254+
- Highlight positive aspects of the implementation
255+
- Note any recurring themes across files
256+
```
257+
258+
### Inline Comment Syntax:
259+
```
260+
<COMMENT>
261+
🟡 Brief issue description
262+
```suggestion
263+
corrected_code_here
264+
```
265+
</COMMENT>
266+
```
267+
268+
### Severity Levels:
269+
- 🟢 for low severity
270+
- 🟡 for medium severity
271+
- 🟠 for high severity
272+
- 🔴 for critical severity
273+
274+
### Examples:
275+
276+
**Function naming:**
277+
```
278+
<COMMENT>
279+
🟢 Use camelCase for function names
280+
```suggestion
281+
myFooBarFunction
282+
```
283+
</COMMENT>
284+
```
285+
286+
**Security issue:**
287+
```
288+
<COMMENT>
289+
🔴 Remove hardcoded API key from source code
290+
```suggestion
291+
const apiKey = process.env.API_KEY;
292+
```
293+
</COMMENT>
294+
```
456295
457296
- name: 'Post PR review failure comment'
458297
if: |-

0 commit comments

Comments
 (0)