github-actions[bot] commented on code in PR #40561: URL: https://github.com/apache/beam/pull/40561#discussion_r4263897375
########## .github/workflows/gemini_code_review.yml: ########## @@ -0,0 +1,213 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +name: Gemini Enterprise Code Review + +on: + pull_request: + paths: + - '.github/workflows/gemini_code_review.yml' + pull_request_target: + types: [opened, reopened, ready_for_review] + workflow_dispatch: + inputs: + pr_number: + description: 'Pull Request number to review' + required: true + type: number + +permissions: read-all + +concurrency: + group: gemini-code-review-${{ github.event.pull_request.number || inputs.pr_number }} + cancel-in-progress: true + +jobs: + gemini-review: + name: Gemini Enterprise PR Review + if: github.repository == 'apache/beam' + runs-on: [self-hosted, ubuntu-24.04, main] + timeout-minutes: 15 + permissions: + contents: read + pull-requests: write + + steps: + - name: Setup Node.js + uses: actions/setup-node@v7 + with: + node-version: '20' + + - name: Run Gemini Enterprise Code Review Agent + id: gemini_review + shell: bash + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} Review Comment: **🟠 High**: `@google/gemini-cli` scrubs sensitive environment variables matching `*TOKEN*` (including `GH_TOKEN`) when spawning child processes via `run_shell_command`. As a result, `gh pr view` and `gh pr diff` inside the agent session fail with `Exit Code: 4` (`To get started with GitHub CLI, please run: gh auth login`). Either authenticate `gh` via `gh auth login --with-token <<< "${GH_TOKEN}"` with `GH_CONFIG_DIR` or pre-fetch the PR metadata/diff before invoking `gemini-cli` (or instruct the prompt to use `web_fetch` / `curl` against the public GitHub URLs). ########## .github/workflows/gemini_code_review.yml: ########## @@ -0,0 +1,213 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +name: Gemini Enterprise Code Review + +on: + pull_request: + paths: + - '.github/workflows/gemini_code_review.yml' + pull_request_target: + types: [opened, reopened, ready_for_review] + workflow_dispatch: + inputs: + pr_number: + description: 'Pull Request number to review' + required: true + type: number + +permissions: read-all + +concurrency: + group: gemini-code-review-${{ github.event.pull_request.number || inputs.pr_number }} + cancel-in-progress: true + +jobs: + gemini-review: + name: Gemini Enterprise PR Review + if: github.repository == 'apache/beam' + runs-on: [self-hosted, ubuntu-24.04, main] + timeout-minutes: 15 + permissions: + contents: read + pull-requests: write + + steps: + - name: Setup Node.js + uses: actions/setup-node@v7 + with: + node-version: '20' + + - name: Run Gemini Enterprise Code Review Agent + id: gemini_review + shell: bash + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GEMINI_CLI_TRUST_WORKSPACE: 'true' + GEMINI_FORCE_FILE_STORAGE: 'true' + GOOGLE_GENAI_USE_VERTEXAI: 'true' + GOOGLE_CLOUD_PROJECT: ${{ secrets.GCP_PROJECT_ID || 'apache-beam-testing' }} + GOOGLE_CLOUD_LOCATION: 'global' + GEMINI_MODEL: ${{ vars.GEMINI_MODEL || 'gemini-4-argon' }} + PR_NUMBER: ${{ github.event.pull_request.number || inputs.pr_number }} + REPOSITORY: ${{ github.repository }} + run: | + set -euo pipefail + + PR_URL="https://github.com/${REPOSITORY}/pull/${PR_NUMBER}" + + mkdir -p .gemini + cat << 'EOF' > .gemini/settings.json + { + "model": { + "maxSessionTurns": 25 + }, + "experimental": { + "directWebFetch": true + }, + "tools": { + "core": [ + "web_fetch", + "run_shell_command(gh pr)", + "run_shell_command(gh api)", + "run_shell_command(curl)" + ] + } + } + EOF + + cat << EOF > prompt.txt + You are an autonomous Apache Beam code review agent running on the Gemini Enterprise Agent Platform. + Review Pull Request: ${PR_URL} + + Use \`gh pr view ${PR_URL}\` and \`gh pr diff ${PR_URL}\` to inspect the pull request metadata and diff. + + Respond with ONLY a single valid JSON object matching this exact schema (no markdown prose outside the JSON): + { + "summary": "## 📋 Review Summary\n\n2-3 sentence high-level assessment.\n\n## 🔍 General Feedback\n- Key architectural or cross-file observations.", + "comments": [ + { + "path": "relative/path/to/file.ext", + "line": 123, + "side": "RIGHT", + "severity": "🟠 High", + "body": "Clear explanation of why this is an issue and how to fix it.", + "suggestion": "optional exact replacement line(s) without backticks, or null" + } + ] + } + EOF + + npx --yes @google/gemini-cli@latest \ + --yolo \ + --model "${GEMINI_MODEL}" \ + --prompt "$(cat prompt.txt)" \ + --output-format json \ + < /dev/null \ + > gemini_raw_output.json + + if jq -e . gemini_raw_output.json >/dev/null 2>&1; then + jq -r '.response // ""' gemini_raw_output.json > gemini_response.txt + else + cp gemini_raw_output.json gemini_response.txt + fi + + - name: Post PR Review to GitHub + uses: actions/github-script@v9 + env: + PR_NUMBER: ${{ github.event.pull_request.number || inputs.pr_number }} + with: + script: | + const fs = require('fs'); + const prNumber = Number(process.env.PR_NUMBER); + const rawResponse = fs.existsSync('gemini_response.txt') + ? fs.readFileSync('gemini_response.txt', 'utf8').trim() + : ''; + if (!rawResponse) { + core.warning('Gemini agent returned an empty response; skipping PR review submission.'); + return; + } + + let parsed; + const fencedMatch = rawResponse.match(/```(?:json)?\s*([\s\S]*?)```/i); Review Comment: **🟠 High**: Using a non-greedy regex `/```(?:json)?\s*([\s\S]*?)```/i` to extract JSON from a fenced code block will truncate the payload prematurely if any review comment `body` or `suggestion` inside the JSON string itself contains triple backticks (` ``` `). Prefer matching only outer fences anchored to the start/end of `rawResponse`, or parsing `rawResponse` directly before falling back to fence stripping. ```suggestion const fencedMatch = rawResponse.match(/^```(?:json)?\s*([\s\S]*)```$/i); const candidateJson = fencedMatch ? fencedMatch[1].trim() : rawResponse; ``` ########## .github/workflows/gemini_code_review.yml: ########## @@ -0,0 +1,213 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +name: Gemini Enterprise Code Review + +on: + pull_request: + paths: + - '.github/workflows/gemini_code_review.yml' + pull_request_target: + types: [opened, reopened, ready_for_review] + workflow_dispatch: + inputs: + pr_number: + description: 'Pull Request number to review' + required: true + type: number + +permissions: read-all + +concurrency: + group: gemini-code-review-${{ github.event.pull_request.number || inputs.pr_number }} + cancel-in-progress: true + +jobs: + gemini-review: + name: Gemini Enterprise PR Review + if: github.repository == 'apache/beam' + runs-on: [self-hosted, ubuntu-24.04, main] + timeout-minutes: 15 + permissions: + contents: read + pull-requests: write + + steps: + - name: Setup Node.js + uses: actions/setup-node@v7 + with: + node-version: '20' + + - name: Run Gemini Enterprise Code Review Agent + id: gemini_review + shell: bash + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GEMINI_CLI_TRUST_WORKSPACE: 'true' + GEMINI_FORCE_FILE_STORAGE: 'true' + GOOGLE_GENAI_USE_VERTEXAI: 'true' + GOOGLE_CLOUD_PROJECT: ${{ secrets.GCP_PROJECT_ID || 'apache-beam-testing' }} + GOOGLE_CLOUD_LOCATION: 'global' + GEMINI_MODEL: ${{ vars.GEMINI_MODEL || 'gemini-4-argon' }} + PR_NUMBER: ${{ github.event.pull_request.number || inputs.pr_number }} + REPOSITORY: ${{ github.repository }} + run: | + set -euo pipefail + + PR_URL="https://github.com/${REPOSITORY}/pull/${PR_NUMBER}" + + mkdir -p .gemini + cat << 'EOF' > .gemini/settings.json + { + "model": { + "maxSessionTurns": 25 + }, + "experimental": { + "directWebFetch": true + }, + "tools": { + "core": [ + "web_fetch", + "run_shell_command(gh pr)", + "run_shell_command(gh api)", + "run_shell_command(curl)" + ] + } + } + EOF + + cat << EOF > prompt.txt + You are an autonomous Apache Beam code review agent running on the Gemini Enterprise Agent Platform. + Review Pull Request: ${PR_URL} + + Use \`gh pr view ${PR_URL}\` and \`gh pr diff ${PR_URL}\` to inspect the pull request metadata and diff. + + Respond with ONLY a single valid JSON object matching this exact schema (no markdown prose outside the JSON): + { + "summary": "## 📋 Review Summary\n\n2-3 sentence high-level assessment.\n\n## 🔍 General Feedback\n- Key architectural or cross-file observations.", + "comments": [ + { + "path": "relative/path/to/file.ext", + "line": 123, + "side": "RIGHT", + "severity": "🟠 High", + "body": "Clear explanation of why this is an issue and how to fix it.", + "suggestion": "optional exact replacement line(s) without backticks, or null" + } + ] + } + EOF + + npx --yes @google/gemini-cli@latest \ + --yolo \ + --model "${GEMINI_MODEL}" \ + --prompt "$(cat prompt.txt)" \ + --output-format json \ + < /dev/null \ + > gemini_raw_output.json + + if jq -e . gemini_raw_output.json >/dev/null 2>&1; then + jq -r '.response // ""' gemini_raw_output.json > gemini_response.txt + else + cp gemini_raw_output.json gemini_response.txt + fi + + - name: Post PR Review to GitHub + uses: actions/github-script@v9 + env: + PR_NUMBER: ${{ github.event.pull_request.number || inputs.pr_number }} + with: + script: | + const fs = require('fs'); + const prNumber = Number(process.env.PR_NUMBER); + const rawResponse = fs.existsSync('gemini_response.txt') + ? fs.readFileSync('gemini_response.txt', 'utf8').trim() + : ''; + if (!rawResponse) { + core.warning('Gemini agent returned an empty response; skipping PR review submission.'); + return; + } + + let parsed; + const fencedMatch = rawResponse.match(/```(?:json)?\s*([\s\S]*?)```/i); + const candidateJson = fencedMatch ? fencedMatch[1].trim() : rawResponse; + try { + parsed = JSON.parse(candidateJson); + } catch (firstErr) { + const firstBrace = rawResponse.indexOf('{'); + const lastBrace = rawResponse.lastIndexOf('}'); + if (firstBrace !== -1 && lastBrace > firstBrace) { + parsed = JSON.parse(rawResponse.slice(firstBrace, lastBrace + 1)); Review Comment: **🟡 Medium**: If `JSON.parse(rawResponse.slice(firstBrace, lastBrace + 1))` throws a `SyntaxError` (for example, if the model outputs unstructured prose containing `{` and `}`), this `catch` block will throw an unhandled exception and fail the workflow step instead of falling back to `{ summary: rawResponse, comments: [] }`. Wrap the inner `JSON.parse` in its own `try/catch`. ```suggestion if (firstBrace !== -1 && lastBrace > firstBrace) { try { parsed = JSON.parse(rawResponse.slice(firstBrace, lastBrace + 1)); } catch { parsed = { summary: rawResponse, comments: [] }; } } else { ``` ########## .github/workflows/gemini_code_review.yml: ########## @@ -0,0 +1,213 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +name: Gemini Enterprise Code Review + +on: + pull_request: + paths: + - '.github/workflows/gemini_code_review.yml' + pull_request_target: + types: [opened, reopened, ready_for_review] + workflow_dispatch: + inputs: + pr_number: + description: 'Pull Request number to review' + required: true + type: number + +permissions: read-all + +concurrency: + group: gemini-code-review-${{ github.event.pull_request.number || inputs.pr_number }} + cancel-in-progress: true + +jobs: + gemini-review: + name: Gemini Enterprise PR Review + if: github.repository == 'apache/beam' + runs-on: [self-hosted, ubuntu-24.04, main] + timeout-minutes: 15 + permissions: + contents: read + pull-requests: write + + steps: + - name: Setup Node.js + uses: actions/setup-node@v7 + with: + node-version: '20' + + - name: Run Gemini Enterprise Code Review Agent + id: gemini_review + shell: bash + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GEMINI_CLI_TRUST_WORKSPACE: 'true' + GEMINI_FORCE_FILE_STORAGE: 'true' + GOOGLE_GENAI_USE_VERTEXAI: 'true' + GOOGLE_CLOUD_PROJECT: ${{ secrets.GCP_PROJECT_ID || 'apache-beam-testing' }} + GOOGLE_CLOUD_LOCATION: 'global' + GEMINI_MODEL: ${{ vars.GEMINI_MODEL || 'gemini-4-argon' }} + PR_NUMBER: ${{ github.event.pull_request.number || inputs.pr_number }} + REPOSITORY: ${{ github.repository }} + run: | + set -euo pipefail + + PR_URL="https://github.com/${REPOSITORY}/pull/${PR_NUMBER}" + + mkdir -p .gemini + cat << 'EOF' > .gemini/settings.json + { + "model": { + "maxSessionTurns": 25 + }, + "experimental": { + "directWebFetch": true + }, + "tools": { + "core": [ + "web_fetch", + "run_shell_command(gh pr)", + "run_shell_command(gh api)", + "run_shell_command(curl)" + ] + } + } + EOF + + cat << EOF > prompt.txt + You are an autonomous Apache Beam code review agent running on the Gemini Enterprise Agent Platform. + Review Pull Request: ${PR_URL} + + Use \`gh pr view ${PR_URL}\` and \`gh pr diff ${PR_URL}\` to inspect the pull request metadata and diff. + + Respond with ONLY a single valid JSON object matching this exact schema (no markdown prose outside the JSON): + { + "summary": "## 📋 Review Summary\n\n2-3 sentence high-level assessment.\n\n## 🔍 General Feedback\n- Key architectural or cross-file observations.", + "comments": [ + { + "path": "relative/path/to/file.ext", + "line": 123, + "side": "RIGHT", + "severity": "🟠 High", + "body": "Clear explanation of why this is an issue and how to fix it.", + "suggestion": "optional exact replacement line(s) without backticks, or null" + } + ] + } + EOF + + npx --yes @google/gemini-cli@latest \ + --yolo \ + --model "${GEMINI_MODEL}" \ + --prompt "$(cat prompt.txt)" \ + --output-format json \ + < /dev/null \ + > gemini_raw_output.json + + if jq -e . gemini_raw_output.json >/dev/null 2>&1; then + jq -r '.response // ""' gemini_raw_output.json > gemini_response.txt + else + cp gemini_raw_output.json gemini_response.txt + fi + + - name: Post PR Review to GitHub + uses: actions/github-script@v9 + env: + PR_NUMBER: ${{ github.event.pull_request.number || inputs.pr_number }} + with: + script: | + const fs = require('fs'); + const prNumber = Number(process.env.PR_NUMBER); + const rawResponse = fs.existsSync('gemini_response.txt') + ? fs.readFileSync('gemini_response.txt', 'utf8').trim() + : ''; + if (!rawResponse) { + core.warning('Gemini agent returned an empty response; skipping PR review submission.'); + return; + } + + let parsed; + const fencedMatch = rawResponse.match(/```(?:json)?\s*([\s\S]*?)```/i); + const candidateJson = fencedMatch ? fencedMatch[1].trim() : rawResponse; + try { + parsed = JSON.parse(candidateJson); + } catch (firstErr) { + const firstBrace = rawResponse.indexOf('{'); + const lastBrace = rawResponse.lastIndexOf('}'); + if (firstBrace !== -1 && lastBrace > firstBrace) { + parsed = JSON.parse(rawResponse.slice(firstBrace, lastBrace + 1)); + } else { + parsed = { summary: rawResponse, comments: [] }; + } + } + + const inlineComments = []; + if (Array.isArray(parsed.comments)) { + for (const item of parsed.comments) { + if (!item || !item.path || !item.body || !Number.isInteger(Number(item.line))) { Review Comment: **🟡 Medium**: `Number(item.line)` will evaluate to `0` or a negative integer if the model returns `0` or negative line numbers, which `Number.isInteger()` accepts, causing GitHub's `pulls.createReview` API to reject the entire batch of inline comments with `422 Unprocessable Entity`. Ensure `line > 0`. ```suggestion if (!item || !item.path || !item.body || !Number.isInteger(Number(item.line)) || Number(item.line) <= 0) { ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
