From af3a59e3e7fcd1325cf0d3ed101890dbe15c884b Mon Sep 17 00:00:00 2001 From: q4rk Date: Tue, 19 May 2026 00:04:07 +0000 Subject: [PATCH 1/3] Add detailed comments and explain security guardrails in workflow --- .github/workflows/gemini-review.yml | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/.github/workflows/gemini-review.yml b/.github/workflows/gemini-review.yml index 79a5bc2..f63d566 100644 --- a/.github/workflows/gemini-review.yml +++ b/.github/workflows/gemini-review.yml @@ -1,12 +1,17 @@ +# This workflow performs automated code reviews on Pull Requests using Gemini AI. +# It can be triggered automatically on PR events or manually via comments. name: 'Gemini PR Review' on: + # Trigger automatically when a PR is opened or updated (synchronized) pull_request: types: [opened, synchronize] + # Trigger when a comment is created on an issue/PR issue_comment: types: [created] concurrency: + # Ensure only one review run per PR/Issue at a time to avoid conflicts and spam group: '${{ github.workflow }}-${{ github.event.pull_request.number || github.event.issue.number }}' cancel-in-progress: true @@ -17,7 +22,12 @@ permissions: jobs: review: - # Only run on PRs (not forks) OR on PR comments starting with the command from authorized users + # SECURITY GUARDRAILS: + # 1. For pull_request events: Only run if it is NOT a fork to prevent secrets exposure to untrusted code. + # 2. For issue_comment events: + # - Must be on a Pull Request (github.event.issue.pull_request exists). + # - Comment must start with '@gemini-cli /review'. + # - User must be an authorized collaborator (OWNER, MEMBER, COLLABORATOR) to prevent unauthorized trigger. 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)) @@ -29,6 +39,7 @@ jobs: persist-credentials: false fetch-depth: 0 + # Acknowledge comment triggers immediately with an 'eyes' reaction to give user feedback - name: Acknowledge Command (Reaction) if: github.event_name == 'issue_comment' env: @@ -36,6 +47,7 @@ jobs: run: | gh api -X POST /repos/${{ github.repository }}/issues/comments/${{ github.event.comment.id }}/reactions -f content='eyes' + # Prepare the context and resolve placeholders in the prompt template - name: Extract Context & Load Configs id: config working-directory: .gemini/ci/pr-review @@ -44,13 +56,15 @@ jobs: PULL_REQUEST_NUMBER: ${{ github.event.pull_request.number || github.event.issue.number }} RAW_COMMENT: ${{ github.event.comment.body || '' }} run: | - # Extract additional context from the comment (if any) + # Extract additional context from the comment (if any) after the command + # E.g. '@gemini-cli /review focus on security' -> ADDITIONAL_CONTEXT="focus on security" 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 REPOSITORY PULL_REQUEST_NUMBER ADDITIONAL_CONTEXT + { echo "settings< Date: Tue, 19 May 2026 00:21:37 +0000 Subject: [PATCH 2/3] fixes --- .gemini/ci/pr-review/PROMPT.md | 18 +++++++----------- .github/workflows/gemini-review.yml | 22 ++++------------------ 2 files changed, 11 insertions(+), 29 deletions(-) diff --git a/.gemini/ci/pr-review/PROMPT.md b/.gemini/ci/pr-review/PROMPT.md index 4453eff..c9aca22 100644 --- a/.gemini/ci/pr-review/PROMPT.md +++ b/.gemini/ci/pr-review/PROMPT.md @@ -1,19 +1,12 @@ - - **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. - - # Pull Request Review Guidelines You are performing an automated Pull Request review for this repository. To ensure high-quality, clean, and non-spammy feedback, you MUST strictly adhere to the following rules: ## 1. Environment & Context + **GitHub Repository**: ${REPOSITORY} + **Pull Request Number**: ${PULL_REQUEST_NUMBER} + **Additional User Instructions**: ${ADDITIONAL_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, you MUST use these exact literal values: @@ -21,7 +14,10 @@ To ensure high-quality, clean, and non-spammy feedback, you MUST strictly adhere - `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 +## 2. Skill Activation +The `code-review-commons` skill is ALREADY loaded and active. Proceed directly to analyzing the diffs using the `github` MCP tools. + +## 3. 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. \ No newline at end of file diff --git a/.github/workflows/gemini-review.yml b/.github/workflows/gemini-review.yml index f63d566..9ebe2bf 100644 --- a/.github/workflows/gemini-review.yml +++ b/.github/workflows/gemini-review.yml @@ -1,17 +1,12 @@ -# This workflow performs automated code reviews on Pull Requests using Gemini AI. -# It can be triggered automatically on PR events or manually via comments. name: 'Gemini PR Review' on: - # Trigger automatically when a PR is opened or updated (synchronized) pull_request: types: [opened, synchronize] - # Trigger when a comment is created on an issue/PR issue_comment: types: [created] concurrency: - # Ensure only one review run per PR/Issue at a time to avoid conflicts and spam group: '${{ github.workflow }}-${{ github.event.pull_request.number || github.event.issue.number }}' cancel-in-progress: true @@ -22,12 +17,7 @@ permissions: jobs: review: - # SECURITY GUARDRAILS: - # 1. For pull_request events: Only run if it is NOT a fork to prevent secrets exposure to untrusted code. - # 2. For issue_comment events: - # - Must be on a Pull Request (github.event.issue.pull_request exists). - # - Comment must start with '@gemini-cli /review'. - # - User must be an authorized collaborator (OWNER, MEMBER, COLLABORATOR) to prevent unauthorized trigger. + # 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)) @@ -39,7 +29,6 @@ jobs: persist-credentials: false fetch-depth: 0 - # Acknowledge comment triggers immediately with an 'eyes' reaction to give user feedback - name: Acknowledge Command (Reaction) if: github.event_name == 'issue_comment' env: @@ -47,7 +36,6 @@ jobs: run: | gh api -X POST /repos/${{ github.repository }}/issues/comments/${{ github.event.comment.id }}/reactions -f content='eyes' - # Prepare the context and resolve placeholders in the prompt template - name: Extract Context & Load Configs id: config working-directory: .gemini/ci/pr-review @@ -57,7 +45,7 @@ jobs: RAW_COMMENT: ${{ github.event.comment.body || '' }} run: | # Extract additional context from the comment (if any) after the command - # E.g. '@gemini-cli /review focus on security' -> ADDITIONAL_CONTEXT="focus on security" + # e.g. '@gemini-cli /review focus on security' -> ADDITIONAL_CONTEXT="focus on security" ADDITIONAL_CONTEXT="None" if [[ "$RAW_COMMENT" == *"@gemini-cli /review"* ]]; then ADDITIONAL_CONTEXT=$(echo "$RAW_COMMENT" | sed 's/^@gemini-cli \/review//' | xargs) @@ -76,11 +64,9 @@ jobs: echo "" echo "EOF_DELIM" - # CRITICAL FIX: Use envsubst to resolve placeholders ($REPOSITORY, $PULL_REQUEST_NUMBER, $ADDITIONAL_CONTEXT) - # in PROMPT.md before passing it. This prevents the model from getting literal placeholders - # and falling back to example values (which caused it to review wrong PRs in the past). - # We explicitly scope envsubst to only replace these three variables for safety. echo "prompt< Date: Tue, 19 May 2026 02:23:41 +0200 Subject: [PATCH 3/3] Update .gemini/ci/pr-review/PROMPT.md Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- .gemini/ci/pr-review/PROMPT.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.gemini/ci/pr-review/PROMPT.md b/.gemini/ci/pr-review/PROMPT.md index c9aca22..f2b88d0 100644 --- a/.gemini/ci/pr-review/PROMPT.md +++ b/.gemini/ci/pr-review/PROMPT.md @@ -8,7 +8,9 @@ To ensure high-quality, clean, and non-spammy feedback, you MUST strictly adhere **Pull Request Number**: ${PULL_REQUEST_NUMBER} **Additional User Instructions**: ${ADDITIONAL_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. + **GitHub Repository**: $REPOSITORY + **Pull Request Number**: $PULL_REQUEST_NUMBER + **Additional User Instructions**: $ADDITIONAL_CONTEXT - 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. You MUST pass it as a number, do NOT wrap it in quotes!)