Skip to content

Commit d1a19d7

Browse files
ci(small): Allow manual Gemini invocation to override global disable flag (#9501)
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 4ec9a54 commit d1a19d7

File tree

3 files changed

+40
-14
lines changed

3 files changed

+40
-14
lines changed

.github/workflows/pr-enrichment.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434
steps:
3535
- uses: actions/checkout@v4
3636
with:
37-
ref: refs/pull/${{ inputs.pr_number || github.event.pull_request.number }}/head
37+
ref: refs/pull/${{ inputs.pr_number || github.event.pull_request.number || github.event.issue.number }}/head
3838
fetch-depth: 0
3939

4040
- name: Setup Environment

scripts/decide-review-strategy.sh

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ set -e
2323
: "${QUALITY_GATE_BOT_USERNAMES:=github-actions[bot]}"
2424
# This variable is optional and may not be present for all event types.
2525
: "${COMMENT_BODY:=}"
26+
: "${GEMINI_ENABLE_PR_REVIEW:=true}"
2627

2728

2829
# --- Initial State ---
@@ -31,23 +32,23 @@ SKIP_REASON="no criteria met"
3132

3233
# --- Main Logic ---
3334

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-
42-
# Check 1: Manual Override
35+
# Check 1: Manual Override (Highest Priority)
4336
# A manual trigger (e.g., a specific comment) always forces a review, bypassing all other checks.
44-
if [[ "$TRIGGER_EVENT" == "comment" && ( "$COMMENT_BODY" == *@gemini-bot* || "$COMMENT_BODY" == *@jules* ) ]]; then
45-
echo "::info::Manual review triggered by comment. Bypassing all checks."
37+
if [[ "$TRIGGER_EVENT" == "comment" && ( "${COMMENT_BODY,,}" == *@gemini-bot* || "${COMMENT_BODY,,}" == *@jules* ) ]]; then
38+
echo "::info::Manual review triggered by comment. Bypassing all checks and global toggles."
4639
echo "needs-review=true" >> "$GITHUB_OUTPUT"
4740
echo "skip-reason=" >> "$GITHUB_OUTPUT"
4841
exit 0
4942
fi
5043

44+
# Check 1b: Global Toggle
45+
if [[ "$GEMINI_ENABLE_PR_REVIEW" == "false" ]]; then
46+
echo "::info::Gemini review is disabled via GEMINI_ENABLE_PR_REVIEW."
47+
echo "needs-review=false" >> "$GITHUB_OUTPUT"
48+
echo "skip-reason=Gemini review is globally disabled" >> "$GITHUB_OUTPUT"
49+
exit 0
50+
fi
51+
5152
# Check 2: Comment Count Limit
5253
# Prevents reviews on PRs that are excessively noisy.
5354
COMMENT_COUNT=$(gh pr view "$PR_NUMBER" --json comments --jq '.comments | length')

tests/unit/decide-review-strategy.bats

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ setup() {
77
# Reset all environment variables to a clean slate
88
unset TRIGGER_EVENT ACTION_TYPE COMMENT_BODY PR_NUMBER BASE_SHA HEAD_SHA \
99
PR_QUALITY_RESULT MAX_COMMENTS REVIEW_THROTTLE_MINUTES BOT_USERNAME \
10-
QUALITY_GATE_BOT_USERNAMES MOCK_GH_COMMENTS_JSON
10+
QUALITY_GATE_BOT_USERNAMES MOCK_GH_COMMENTS_JSON GEMINI_ENABLE_PR_REVIEW
1111
}
1212

1313
@test "should trigger review on manual override" {
@@ -23,6 +23,18 @@ setup() {
2323
assert_output "skip-reason" ""
2424
}
2525

26+
@test "should trigger review on case-insensitive manual override" {
27+
export TRIGGER_EVENT="comment"
28+
export ACTION_TYPE="created"
29+
export COMMENT_BODY="@Gemini-Bot review"
30+
31+
run_script
32+
33+
[ "$status" -eq 0 ]
34+
assert_output "needs-review" "true"
35+
assert_output "skip-reason" ""
36+
}
37+
2638
@test "should skip review when comment limit is exceeded" {
2739
export MAX_COMMENTS=1
2840
export MOCK_GH_COMMENTS_JSON='[{"body":"a"},{"body":"b"}]'
@@ -112,7 +124,20 @@ setup() {
112124

113125
[ "$status" -eq 0 ]
114126
assert_output "needs-review" "false"
115-
assert_output "skip-reason" "Gemini review is disabled"
127+
assert_output "skip-reason" "Gemini review is globally disabled"
128+
}
129+
130+
@test "should trigger review on manual override even if GEMINI_ENABLE_PR_REVIEW is false" {
131+
export GEMINI_ENABLE_PR_REVIEW="false"
132+
export TRIGGER_EVENT="comment"
133+
export ACTION_TYPE="created"
134+
export COMMENT_BODY="@gemini-bot review"
135+
136+
run_script
137+
138+
[ "$status" -eq 0 ]
139+
assert_output "needs-review" "true"
140+
assert_output "skip-reason" ""
116141
}
117142

118143
# Helper function to assert the output of the script

0 commit comments

Comments
 (0)