Skip to content

Commit 8c5bf02

Browse files
feat(medium): Add GitHub Actions variables to control Gemini API usage (#9408)
Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com> Co-authored-by: arii <342438+arii@users.noreply.github.com>
1 parent 176a72a commit 8c5bf02

9 files changed

Lines changed: 66 additions & 30 deletions

.github/workflows/gemini-coder.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ permissions:
7373

7474
jobs:
7575
ai-developer:
76-
if: (github.event_name == 'workflow_dispatch') || (github.event.label.name == 'auto-code')
76+
if: vars.GEMINI_ENABLE_CODER != 'false' && ((github.event_name == 'workflow_dispatch') || (github.event.label.name == 'auto-code'))
7777
runs-on: self-hosted
7878

7979
steps:

.github/workflows/gemini-triage.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
triage:
2626
# This job runs for new issues.
2727
# It uses a Gemini agent to analyze the issue and provide a detailed triage.
28-
if: github.event_name == 'issues' && github.actor != 'ari-party-bot'
28+
if: vars.GEMINI_ENABLE_TRIAGE != 'false' && github.event_name == 'issues' && github.actor != 'ari-party-bot'
2929
runs-on: self-hosted
3030
steps:
3131
- uses: actions/checkout@v4

.github/workflows/pr-quality.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ jobs:
217217
shell: bash
218218
env:
219219
GEMINI_API_KEY: ${{ secrets.GEMINI_API_KEY }}
220+
GEMINI_ENABLE_SLOP_CHECK: ${{ vars.GEMINI_ENABLE_SLOP_CHECK }}
220221
run: |
221222
chmod +x ./scripts/ci-check-slop.sh
222223
./scripts/ci-check-slop.sh

.github/workflows/reusable-create-review-issues.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ permissions:
3030

3131
jobs:
3232
create-review-issues:
33+
if: vars.GEMINI_ENABLE_REVIEW_ISSUES != 'false'
3334
runs-on: ubuntu-latest
3435
name: Create Issues from Gemini Review
3536

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,15 @@ jobs:
9494
MAX_COMMENTS: 60
9595
REVIEW_THROTTLE_MINUTES: 30
9696
BOT_USERNAME: 'gemini-bot'
97+
GEMINI_ENABLE_PR_REVIEW: ${{ vars.GEMINI_ENABLE_PR_REVIEW }}
9798
run: |
9899
chmod +x ./scripts/decide-review-strategy.sh
99100
./scripts/decide-review-strategy.sh
100101
101102
gemini-review:
102103
name: Execute Gemini Review
103104
needs: analyze-changes
104-
if: needs.analyze-changes.outputs.needs-review == 'true'
105+
if: vars.GEMINI_ENABLE_PR_REVIEW != 'false' && needs.analyze-changes.outputs.needs-review == 'true'
105106
runs-on: ubuntu-latest
106107
outputs:
107108
review_performed: ${{ steps.upload_artifact.outcome == 'success' }}

lib/env.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ const envSchema = z
4444
WEBSOCKET_WATCHDOG_INTERVAL: z.coerce.number().default(30000),
4545
NEXT_PUBLIC_BLUETOOTH_MAX_RECONNECT_ATTEMPTS: z.coerce.number().default(8),
4646
GEMINI_MODEL_FALLBACKS: z.string().optional(),
47+
GEMINI_ENABLE_TRIAGE: z.string().default('true'),
48+
GEMINI_ENABLE_CODER: z.string().default('true'),
49+
GEMINI_ENABLE_PR_REVIEW: z.string().default('true'),
50+
GEMINI_ENABLE_REVIEW_ISSUES: z.string().default('true'),
51+
GEMINI_ENABLE_SLOP_CHECK: z.string().default('true'),
52+
GEMINI_RATE_LIMIT_PER_DAY: z.coerce.number().optional(),
4753
ANALYZE: z.string().optional(),
4854
TESTING: z.string().optional(),
4955
IS_DEPLOYMENT: z.string().optional(),

scripts/ci-check-slop.sh

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -45,26 +45,32 @@ if ! LOC_STATS=$(git diff --stat "$DIFF_TARGET" 2>&1); then
4545
fi
4646
echo "$LOC_STATS"
4747

48-
echo "Requesting Gemini feedback..."
48+
if [ "${GEMINI_ENABLE_SLOP_CHECK:-true}" == "false" ]; then
49+
echo "⚠️ Gemini slop check disabled via GEMINI_ENABLE_SLOP_CHECK" >&2
50+
# We still want to generate the report based on the regex detector if it ran,
51+
# but we skip the Gemini API call.
52+
echo "Gemini feedback skipped (disabled via environment variable)." > "$GEMINI_SLOP_LOG"
53+
else
54+
echo "Requesting Gemini feedback..."
4955

50-
# Generate Diff (limit size to 100KB to be safe)
51-
if [ -z "$DIFF_ERROR" ]; then
56+
# Generate Diff (limit size to 100KB to be safe)
57+
if [ -z "$DIFF_ERROR" ]; then
5258
# Capture diff to file, respecting size limit
5359
if ! git diff "$DIFF_TARGET" | head -c "$DIFF_MAX_SIZE" > "$DIFF_FILE"; then
54-
echo "Diff generation failed." > "$DIFF_FILE"
60+
echo "Diff generation failed." > "$DIFF_FILE"
5561
else
56-
# Check if we hit the limit
57-
ACTUAL_SIZE=$(wc -c < "$DIFF_FILE")
58-
if [ "$ACTUAL_SIZE" -ge "$DIFF_MAX_SIZE" ]; then
59-
echo "⚠️ Warning: Diff truncated to ${DIFF_MAX_SIZE} bytes." >&2
60-
echo "... (Diff truncated at ${DIFF_MAX_SIZE} bytes) ..." >> "$DIFF_FILE"
61-
fi
62+
# Check if we hit the limit
63+
ACTUAL_SIZE=$(wc -c < "$DIFF_FILE")
64+
if [ "$ACTUAL_SIZE" -ge "$DIFF_MAX_SIZE" ]; then
65+
echo "⚠️ Warning: Diff truncated to ${DIFF_MAX_SIZE} bytes." >&2
66+
echo "... (Diff truncated at ${DIFF_MAX_SIZE} bytes) ..." >> "$DIFF_FILE"
67+
fi
6268
fi
63-
else
69+
else
6470
echo "Diff generation skipped due to previous error: $DIFF_ERROR" > "$DIFF_FILE"
65-
fi
71+
fi
6672

67-
cat > "$TASK_FILE" <<EOF
73+
cat > "$TASK_FILE" <<EOF
6874
Review the following code changes for "slop" (low-quality, repetitive, or filler content).
6975
We have already run a regex-based detector.
7076
@@ -86,20 +92,21 @@ Please provide a concise assessment of the changes.
8692
Keep your response short and focused on quality/slop.
8793
EOF
8894

89-
if [ -z "$GEMINI_API_KEY" ]; then
90-
echo "⚠️ GEMINI_API_KEY not set. Skipping Gemini feedback." >&2
91-
echo "Gemini feedback skipped (missing API key)." > "$GEMINI_SLOP_LOG"
92-
else
93-
echo "Invoking Gemini client..."
94-
GEMINI_EXIT_CODE=0
95-
pnpm tsx scripts/gemini-client.ts \
96-
--task-file "$TASK_FILE" \
97-
--context "$DIFF_FILE" \
98-
--output "$GEMINI_SLOP_LOG" || GEMINI_EXIT_CODE=$?
99-
100-
if [ $GEMINI_EXIT_CODE -ne 0 ]; then
101-
echo "⚠️ Gemini client failed. Continuing with available reports." >&2
102-
echo "Gemini feedback unavailable (client failed)." > "$GEMINI_SLOP_LOG"
95+
if [ -z "$GEMINI_API_KEY" ]; then
96+
echo "⚠️ GEMINI_API_KEY not set. Skipping Gemini feedback." >&2
97+
echo "Gemini feedback skipped (missing API key)." > "$GEMINI_SLOP_LOG"
98+
else
99+
echo "Invoking Gemini client..."
100+
GEMINI_EXIT_CODE=0
101+
pnpm tsx scripts/gemini-client.ts \
102+
--task-file "$TASK_FILE" \
103+
--context "$DIFF_FILE" \
104+
--output "$GEMINI_SLOP_LOG" || GEMINI_EXIT_CODE=$?
105+
106+
if [ $GEMINI_EXIT_CODE -ne 0 ]; then
107+
echo "⚠️ Gemini client failed. Continuing with available reports." >&2
108+
echo "Gemini feedback unavailable (client failed)." > "$GEMINI_SLOP_LOG"
109+
fi
103110
fi
104111
fi
105112

scripts/decide-review-strategy.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@ SKIP_REASON="no criteria met"
3131

3232
# --- Main Logic ---
3333

34+
# Check 0: Gemini Review Enablement
35+
if [[ "${GEMINI_ENABLE_PR_REVIEW:-true}" == "false" ]]; then
36+
echo "::info::Gemini review is disabled via GEMINI_ENABLE_PR_REVIEW."
37+
echo "needs-review=false" >> "$GITHUB_OUTPUT"
38+
echo "skip-reason=Gemini review is disabled" >> "$GITHUB_OUTPUT"
39+
exit 0
40+
fi
41+
3442
# Check 1: Manual Override
3543
# A manual trigger (e.g., a specific comment) always forces a review, bypassing all other checks.
3644
if [[ "$TRIGGER_EVENT" == "comment" && ( "$COMMENT_BODY" == *@gemini-bot* || "$COMMENT_BODY" == *@jules* ) ]]; then

tests/unit/decide-review-strategy.bats

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,18 @@ setup() {
103103
assert_output "skip-reason" "quality failure with no detailed report (likely static analysis)"
104104
}
105105

106+
@test "should skip review when GEMINI_ENABLE_PR_REVIEW is false" {
107+
export GEMINI_ENABLE_PR_REVIEW="false"
108+
export TRIGGER_EVENT="pull_request"
109+
export ACTION_TYPE="opened"
110+
111+
run_script
112+
113+
[ "$status" -eq 0 ]
114+
assert_output "needs-review" "false"
115+
assert_output "skip-reason" "Gemini review is disabled"
116+
}
117+
106118
# Helper function to assert the output of the script
107119
assert_output() {
108120
local key="$1"

0 commit comments

Comments
 (0)