Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 57 additions & 8 deletions .gemini/ci/pr-review/PROMPT.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,56 @@
<CONTEXT>
**GitHub Repository**: ${REPOSITORY}
**Pull Request Number**: ${PULL_REQUEST_NUMBER}
**Additional User Instructions**: ${ADDITIONAL_CONTEXT}
**Pull Review Details**: use `pull_request_read.get` tool to get the title, body, and metadata about the pull request.
**Code Changes**: call the `pull_request_read.get_diff` tool to retrieve the changes.
</CONTEXT>

<PROTOCOL>
The `code-review-commons` skill is ALREADY loaded and active. Proceed directly to analyzing the diffs using the `github` MCP tools. Then submit review following the exact structure and rules in the `<SUBMIT_REVIEW>` section.
</PROTOCOL>

<SUBMIT_REVIEW>
**Review Comment Formatting**

- **Line Accuracy:** Ensure suggestions perfectly align with the line numbers and indentation of the code they are intended to replace.

- Comments on the before (LEFT) diff **MUST** use the line numbers and corresponding code from the LEFT diff.

- Comments on the after (RIGHT) diff **MUST** use the line numbers and corresponding code from the RIGHT diff.

1. **Create Pending Review:** Call `create_pending_pull_request_review`. Ignore errors like "can only have one pending review per pull request" and proceed to the next step.

2. **Add Comments and Suggestions:** For each formulated review comment, call `add_comment_to_pending_review`.

2a. For each suggested change, structure the comment payload using this exact template:

<COMMENT>
[{{SEVERITY}}] {{COMMENT_TEXT}}

```suggestion
{{CODE_SUGGESTION}}
```
</COMMENT>

2b. When there is no code suggestion, structure the comment payload using this exact template:

<COMMENT>
[{{SEVERITY}}] {{COMMENT_TEXT}}
</COMMENT>

3. **Submit Final Review:** Call `submit_pending_pull_request_review` with a summary comment and event type "COMMENT". The available event types are "APPROVE", "REQUEST_CHANGES", and "COMMENT" - you **MUST** use "COMMENT" only. **DO NOT** use "APPROVE" or "REQUEST_CHANGES" event types. The summary comment **MUST** use this exact markdown format:

## 📋 Review Summary

A brief, high-level assessment of the Pull Request's objective and quality (2-3 sentences).

## 🔍 General Feedback

- A bulleted list of general observations, positive highlights, or recurring patterns not suitable for inline comments.
- Keep this section concise and do not repeat details already covered in inline comments.
</SUBMIT_REVIEW>

# Pull Request Review Guidelines

You are performing an automated Pull Request review for this repository.
Expand All @@ -6,16 +59,12 @@ To ensure high-quality, clean, and non-spammy feedback, you MUST strictly adhere
## 1. Environment & Context
- The target repository name is provided in the `REPOSITORY` environment variable.
- The Pull Request number is provided in the `PULL_REQUEST_NUMBER` environment variable.
- When calling any GitHub MCP tools (such as `pull_request_read.get`, `pull_request_read.get_diff`, `create_pending_pull_request_review`, `add_comment_to_pending_review`, or `submit_pending_pull_request_review`), you MUST read these variables from your environment and pass their exact literal values as arguments:
- `repository`: (as a literal string, e.g. "q4rk/setup_test")
- `pull_request_number`: (as a literal numeric integer, e.g. 5. You MUST pass it as a number, do NOT wrap it in quotes or pass it as a string!)
- When calling any GitHub MCP tools (such as `pull_request_read.get`, `pull_request_read.get_diff`, `create_pending_pull_request_review`, `add_comment_to_pending_review`, or `submit_pending_pull_request_review`), you MUST use these exact literal values:
- `repository`: "${REPOSITORY}"
- `pull_request_number`: ${PULL_REQUEST_NUMBER} (as a literal numeric integer, e.g. 11. You MUST pass it as a number, do NOT wrap it in quotes!)
- **CRITICAL:** Do NOT use placeholder variables, string templates (like `"$REPOSITORY"` or `"$PULL_REQUEST_NUMBER"`), or environment variable references inside your Python tool call arguments. You MUST resolve and pass the literal values directly.

## 2. Skill Activation
- The `code-review-commons` skill is ALREADY loaded and active.
- Do NOT attempt to call `activate_skill` or any other skill loading tools, as they do not exist in your environment. Proceed directly to analyzing the diffs using the `github` MCP tools.

## 3. Anti-Spam Guardrail
## 2. Anti-Spam Guardrail
- **CRITICAL:** First, fetch and read the Pull Request's existing review comments using `pull_request_read`.
- If an issue at a specific file and line has already been pointed out in a previous review comment, **do NOT post a duplicate comment**.
- You must suppress duplicate suggestions to prevent spamming the PR on synchronizing push events. Only post comments for newly introduced changes or unaddressed issues.
21 changes: 18 additions & 3 deletions .github/workflows/gemini-review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,32 @@ jobs:
- name: Load Gemini Configurations for PR Review
id: config
working-directory: .gemini/ci/pr-review
env:
REPOSITORY: ${{ github.repository }}
PULL_REQUEST_NUMBER: ${{ github.event.pull_request.number || github.event.issue.number }}
ADDITIONAL_CONTEXT: ${{ inputs.additional_context }}
run: |
python3 -c '
import os
content = open("PROMPT.md").read()
content = content.replace("${REPOSITORY}", os.environ["REPOSITORY"])
content = content.replace("${PULL_REQUEST_NUMBER}", os.environ["PULL_REQUEST_NUMBER"])
content = content.replace("${ADDITIONAL_CONTEXT}", os.environ.get("ADDITIONAL_CONTEXT", ""))
open("PROMPT_RESOLVED.md", "w").write(content)
'

echo "=== DEBUG: PROMPT_RESOLVED.md ==="
cat PROMPT_RESOLVED.md
echo "=================================="

{
echo "settings<<EOF"
cat settings.json
echo ""
echo "EOF"

echo "prompt<<EOF"
echo "/pr-code-review"
echo ""
cat PROMPT.md
cat PROMPT_RESOLVED.md
echo ""
echo "EOF"

Expand Down
23 changes: 23 additions & 0 deletions poorly_written_code.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import os
import sys

def process(data):
r = []
for i in range(len(data)):
for j in range(len(data)):
if i == j:
continue
if data[i] == data[j]:
if data[i] not in r:
r.append(data[i])

total = 0
for x in r:
total += x

average = total / len(r)

return average, r

print(process([1, 2, 3, 4, 5]))
print(process([1, 2, 2, 3, 4, 4, 5]))
Loading