diff --git a/.gemini/ci/pr-review/PROMPT.md b/.gemini/ci/pr-review/PROMPT.md index f601f28..4453eff 100644 --- a/.gemini/ci/pr-review/PROMPT.md +++ b/.gemini/ci/pr-review/PROMPT.md @@ -1,56 +1,13 @@ - **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. + **GitHub Repository**: ${REPOSITORY} + **Pull Request Number**: ${PULL_REQUEST_NUMBER} + **Additional User Instructions**: ${ADDITIONAL_CONTEXT} -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 `` section. +The `code-review-commons` skill is ALREADY loaded and active. Proceed directly to analyzing the diffs using the `github` MCP tools. - -**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: - - - [{{SEVERITY}}] {{COMMENT_TEXT}} - - ```suggestion - {{CODE_SUGGESTION}} - ``` - - - 2b. When there is no code suggestion, structure the comment payload using this exact template: - - - [{{SEVERITY}}] {{COMMENT_TEXT}} - - -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. - - # Pull Request Review Guidelines You are performing an automated Pull Request review for this repository. @@ -59,10 +16,10 @@ 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 use these exact literal values: +- When calling any GitHub MCP tools, 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. + - `pull_request_number`: ${PULL_REQUEST_NUMBER} (as a literal numeric integer. You MUST pass it as a number, do NOT wrap it in quotes!) +- **CRITICAL:** Do NOT use placeholder variables or string templates inside your Python tool call arguments. ## 2. Anti-Spam Guardrail - **CRITICAL:** First, fetch and read the Pull Request's existing review comments using `pull_request_read`. diff --git a/.github/workflows/gemini-dispatch.yml b/.github/workflows/gemini-dispatch.yml deleted file mode 100644 index 8215133..0000000 --- a/.github/workflows/gemini-dispatch.yml +++ /dev/null @@ -1,141 +0,0 @@ -name: "Gemini Dispatch" - -on: - pull_request_review_comment: - types: - - "created" - pull_request_review: - types: - - "submitted" - pull_request: - types: - - "opened" - issues: - types: - - 'opened' - - 'reopened' - issue_comment: - types: - - 'created' - -defaults: - run: - shell: "bash" - -jobs: - debugger: - if: |- - ${{ fromJSON(vars.GEMINI_DEBUG || vars.ACTIONS_STEP_DEBUG || false) }} - runs-on: "ubuntu-latest" - permissions: - contents: "read" - steps: - - name: "Print context for debugging" - env: - DEBUG_event_name: "${{ github.event_name }}" - DEBUG_event__action: "${{ github.event.action }}" - DEBUG_event__comment__author_association: "${{ github.event.comment.author_association }}" - DEBUG_event__issue__author_association: "${{ github.event.issue.author_association }}" - DEBUG_event__pull_request__author_association: "${{ github.event.pull_request.author_association }}" - DEBUG_event__review__author_association: "${{ github.event.review.author_association }}" - DEBUG_event: "${{ toJSON(github.event) }}" - run: |- - env | grep '^DEBUG_' - - dispatch: - # For PRs: only if not from a fork - # For issues: only on open/reopen - # For comments: only if user types @gemini-cli and is OWNER/MEMBER/COLLABORATOR - if: |- - ( - github.event_name == 'pull_request' && - github.event.pull_request.head.repo.fork == false - ) || ( - github.event_name == 'issues' && - contains(fromJSON('["opened", "reopened"]'), github.event.action) - ) || ( - github.event.sender.type == 'User' && - startsWith(github.event.comment.body || github.event.review.body || github.event.issue.body, '@gemini-cli') && - contains(fromJSON('["OWNER", "MEMBER", "COLLABORATOR"]'), github.event.comment.author_association || github.event.review.author_association || github.event.issue.author_association) - ) - runs-on: "ubuntu-latest" - permissions: - contents: "read" - issues: "write" - pull-requests: "write" - outputs: - command: "${{ steps.extract_command.outputs.command }}" - request: "${{ steps.extract_command.outputs.request }}" - additional_context: "${{ steps.extract_command.outputs.additional_context }}" - issue_number: "${{ github.event.pull_request.number || github.event.issue.number }}" - steps: - - name: "Extract command" - id: "extract_command" - uses: "actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea" # ratchet:actions/github-script@v7 - env: - EVENT_TYPE: "${{ github.event_name }}.${{ github.event.action }}" - REQUEST: "${{ github.event.comment.body || github.event.review.body || github.event.issue.body }}" - with: - script: | - const eventType = process.env.EVENT_TYPE; - const request = process.env.REQUEST; - core.setOutput('request', request); - - if (eventType === 'pull_request.opened') { - core.setOutput('command', 'review'); - } else if (request.startsWith("@gemini-cli /review")) { - core.setOutput('command', 'review'); - const additionalContext = request.replace(/^@gemini-cli \/review/, '').trim(); - core.setOutput('additional_context', additionalContext); - } else { - core.setOutput('command', 'fallthrough'); - } - - - name: "Acknowledge request" - env: - GITHUB_TOKEN: "${{github.token }}" - ISSUE_NUMBER: "${{ github.event.pull_request.number || github.event.issue.number }}" - MESSAGE: |- - 🤖 Hi @${{ github.actor }}, I've received your request, and I'm working on it now! You can track my progress [in the logs](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) for more details. - REPOSITORY: "${{ github.repository }}" - run: |- - gh issue comment "${ISSUE_NUMBER}" \ - --body "${MESSAGE}" \ - --repo "${REPOSITORY}" - - review: - needs: "dispatch" - if: |- - ${{ needs.dispatch.outputs.command == 'review' }} - uses: "./.github/workflows/gemini-review.yml" - permissions: - contents: "read" - issues: "write" - pull-requests: "write" - with: - additional_context: "${{ needs.dispatch.outputs.additional_context }}" - secrets: "inherit" - - fallthrough: - needs: - - "dispatch" - - "review" - if: |- - ${{ always() && !cancelled() && (failure() || needs.dispatch.outputs.command == 'fallthrough') }} - runs-on: "ubuntu-latest" - permissions: - contents: "read" - issues: "write" - pull-requests: "write" - steps: - - name: "Send failure comment" - env: - GITHUB_TOKEN: "${{ github.token }}" - ISSUE_NUMBER: "${{ github.event.pull_request.number || github.event.issue.number }}" - MESSAGE: |- - 🤖 I'm sorry @${{ github.actor }}, but I was unable to process your request. Please [see the logs](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) for more details. - REPOSITORY: "${{ github.repository }}" - run: |- - gh issue comment "${ISSUE_NUMBER}" \ - --body "${MESSAGE}" \ - --repo "${REPOSITORY}" diff --git a/.github/workflows/gemini-review.yml b/.github/workflows/gemini-review.yml index a12a531..b7e0dc0 100644 --- a/.github/workflows/gemini-review.yml +++ b/.github/workflows/gemini-review.yml @@ -1,93 +1,89 @@ -name: 'Gemini Review' +name: 'Gemini PR Review' on: - workflow_call: - inputs: - additional_context: - type: 'string' - description: 'Any additional context from the request' - required: false - + pull_request: + types: [opened, synchronize] + issue_comment: + types: [created] + concurrency: - group: '${{ github.workflow }}-review-${{ github.event_name }}-${{ github.event.pull_request.number || github.event.issue.number }}' + group: '${{ github.workflow }}-${{ github.event.pull_request.number || github.event.issue.number }}' cancel-in-progress: true permissions: contents: read pull-requests: write - -defaults: - run: - shell: 'bash' + issues: write jobs: review: + # Only run on PRs (not forks) OR on PR comments starting with the command from authorized users + if: >- + (github.event_name == 'pull_request' && !github.event.pull_request.head.repo.fork) || + (github.event_name == 'issue_comment' && github.event.issue.pull_request && startsWith(github.event.comment.body, '@gemini-cli /review') && contains(fromJSON('["OWNER", "MEMBER", "COLLABORATOR"]'), github.event.comment.author_association)) runs-on: ubuntu-latest steps: - name: Checkout repository uses: actions/checkout@v4 with: persist-credentials: false - ref: refs/pull/${{ github.event.pull_request.number || github.event.issue.number }}/head fetch-depth: 0 - - name: Load Gemini Configurations for PR Review + - name: Acknowledge Command (Reaction) + if: github.event_name == 'issue_comment' + env: + GH_TOKEN: ${{ github.token }} + run: | + gh api -X POST /repos/${{ github.repository }}/issues/comments/${{ github.event.comment.id }}/reactions -f content='eyes' + + - name: Extract Context & Load Configs 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 }} + RAW_COMMENT: ${{ github.event.comment.body || '' }} 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 "==================================" - + # 1. Extract additional context from the comment (if any) + ADDITIONAL_CONTEXT="None" + if [[ "$RAW_COMMENT" == *"@gemini-cli /review"* ]]; then + ADDITIONAL_CONTEXT=$(echo "$RAW_COMMENT" | sed 's/^@gemini-cli \/review//' | xargs) + [ -z "$ADDITIONAL_CONTEXT" ] && ADDITIONAL_CONTEXT="None" + fi + + # Export variables so envsubst can access them + export REPOSITORY PULL_REQUEST_NUMBER ADDITIONAL_CONTEXT + + # 2. Safely read files and set GitHub Outputs { - echo "settings<> "$GITHUB_OUTPUT" - - name: Run Gemini CLI for PR Review + - name: Run Gemini CLI uses: google-github-actions/run-gemini-cli@v0.1.22 env: - GEMINI_CLI_TRUST_WORKSPACE: true + GEMINI_CLI_TRUST_WORKSPACE: 'true' GITHUB_TOKEN: ${{ github.token }} - ISSUE_TITLE: '${{ github.event.pull_request.title || github.event.issue.title }}' - ISSUE_BODY: '${{ github.event.pull_request.body || github.event.issue.body }}' GEMINI_API_KEY: ${{ secrets.GEMINI_API_KEY }} REPOSITORY: ${{ github.repository }} PULL_REQUEST_NUMBER: ${{ github.event.pull_request.number || github.event.issue.number }} - ADDITIONAL_CONTEXT: '${{ inputs.additional_context }}' with: gemini_api_key: ${{ secrets.GEMINI_API_KEY }} - workflow_name: 'gemini-review' - gemini_cli_version: 'latest' gemini_model: 'gemini-2.5-flash' - # Explicitly set the PR number to handle `issue_comment` triggers (which GitHub treats as issues, not PRs) - github_pr_number: '${{ github.event.pull_request.number }}' + github_pr_number: ${{ github.event.pull_request.number || github.event.issue.number }} prompt: ${{ steps.config.outputs.prompt }} settings: ${{ steps.config.outputs.settings }} - extensions: ${{ steps.config.outputs.extensions }} - gemini_debug: '${{ fromJSON(vars.GEMINI_DEBUG || vars.ACTIONS_STEP_DEBUG || true) }}' \ No newline at end of file + extensions: ${{ steps.config.outputs.extensions }} \ No newline at end of file diff --git a/another_bad_file.py b/another_bad_file.py new file mode 100644 index 0000000..ab47a15 --- /dev/null +++ b/another_bad_file.py @@ -0,0 +1,10 @@ +import sqlite3 + +def get_user_data(username): + conn = sqlite3.connect('users.db') + cursor = conn.cursor() + query = f"SELECT * FROM users WHERE username = '{username}'" + cursor.execute(query) + return cursor.fetchall() + +unused_var = 10