Skip to content

Commit 83269c4

Browse files
ci(small): fix integer expression error in cleanup-branches script (#9565)
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 f8ec2ee commit 83269c4

File tree

3 files changed

+27
-31
lines changed

3 files changed

+27
-31
lines changed

.github/workflows/comment-ops.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ jobs:
3737
# Use case-insensitive grep and ensure outputs are always set if matched.
3838
# We check for commands starting at the beginning of a line to avoid accidental triggers
3939
# from quotes or descriptive text mentioning the bots.
40-
if echo "$BODY" | grep -qiE "^@gemini-bot"; then echo "is_review=true" >> $GITHUB_OUTPUT; fi
40+
if echo "$BODY" | grep -qiE "(^|\r?\n)@(gemini-bot|gemini-review)"; then echo "is_review=true" >> $GITHUB_OUTPUT; fi
4141
if echo "$BODY" | grep -qiE "(^|\r?\n)@pr-squash"; then echo "is_squash=true" >> $GITHUB_OUTPUT; fi
4242
if echo "$BODY" | grep -qiE "(^|\r?\n)@conflict-resolve"; then echo "is_resolve=true" >> $GITHUB_OUTPUT; fi
4343
if echo "$BODY" | grep -qiE "^@gemini-triage"; then echo "is_triage=true" >> $GITHUB_OUTPUT; fi
@@ -46,6 +46,11 @@ jobs:
4646
if echo "$BODY" | grep -qiE "^@gemini-enrich"; then echo "is_enrich=true" >> $GITHUB_OUTPUT; fi
4747
if echo "$BODY" | grep -qiE "^@gemini-help"; then echo "is_help=true" >> $GITHUB_OUTPUT; fi
4848
49+
# Set consolidated trigger flag for status jobs
50+
if echo "$BODY" | grep -qiE "(^|\r?\n)@(gemini-bot|gemini-review|pr-squash|conflict-resolve|gemini-triage|gemini-coder|create-review-issues|gemini-enrich|gemini-help)"; then
51+
echo "is_command_triggered=true" >> $GITHUB_OUTPUT
52+
fi
53+
4954
init-status:
5055
needs: [router]
5156
if: needs.router.outputs.is_command_triggered == 'true'

scripts/cleanup-branches.sh

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,38 +5,27 @@ DAYS_OLD=1
55
EXCLUDE_REGEX="^(gh-pages|leader|HEAD)$"
66
REMOTE="origin"
77

8-
# 1. Update references and prune tracking branches that no longer exist on remote
98
git fetch --prune
109

11-
# Calculate cutoff timestamp
1210
CUTOFF=$(date -d "$DAYS_OLD days ago" +%s)
13-
# Note: On macOS, use: CUTOFF=$(date -v-${DAYS_OLD}d +%s)
1411

1512
echo "Checking for branches older than $DAYS_OLD days with no open PRs..."
1613

17-
# 2. Iterate through remote branches
1814
git for-each-ref --format='%(committerdate:unix) %(refname:short)' refs/remotes/$REMOTE/ | while read -r time ref; do
1915
branch_name="${ref#$REMOTE/}"
2016

21-
# Skip excluded branches
2217
if [[ $branch_name =~ $EXCLUDE_REGEX ]]; then
2318
continue
2419
fi
2520

26-
# Check if branch is older than the cutoff
2721
if [ "$time" -lt "$CUTOFF" ]; then
28-
29-
# Check for open Pull Requests using GitHub CLI
30-
PR_COUNT=$(gh pr list --head "$branch_name" --state open --json number --jq 'length' 2>/dev/null)
31-
32-
# If PR_COUNT is 0 (or command fails, assuming no PR), proceed with deletion
33-
if [ "$PR_COUNT" -eq 0 ] || [ -z "$PR_COUNT" ]; then
22+
PR_COUNT=$(gh pr list --head "$branch_name" --state open --json number --jq 'length' 2>/dev/null || echo 0)
23+
24+
if [ "${PR_COUNT:-0}" -eq 0 ]; then
3425
echo "Deleting stale branch: $branch_name"
3526

36-
# Delete from remote
3727
git push $REMOTE --delete "$branch_name"
3828

39-
# Delete local branch if it exists
4029
if git show-ref --verify --quiet "refs/heads/$branch_name"; then
4130
git branch -D "$branch_name"
4231
fi
@@ -45,4 +34,3 @@ git for-each-ref --format='%(committerdate:unix) %(refname:short)' refs/remotes/
4534
fi
4635
fi
4736
done
48-

scripts/gemini-client.ts

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -350,22 +350,25 @@ export async function generateContentWithFallback({
350350
const errorMessage = (error as Error).message || ''
351351
const errorStatus = (error as { status?: number }).status
352352

353-
const isNotFound = errorMessage.includes('404') || errorStatus === 404
354-
const isBadRequest = errorMessage.includes('400') || errorStatus === 400 // Sometimes invalid model is 400
355-
const isRateLimited = errorMessage.includes('429') || errorStatus === 429
356-
357-
if (isNotFound || isBadRequest || isRateLimited) {
358-
let reason = 'Unknown Error'
359-
if (isRateLimited) {
360-
reason = 'Rate Limited'
361-
} else if (isNotFound) {
362-
reason = 'Not Found'
363-
} else if (isBadRequest) {
364-
reason = 'Invalid Request'
365-
}
366-
const details = reason === 'Unknown Error' ? `: ${errorMessage}` : ''
353+
const RETRIABLE_MAP: Record<number, string> = {
354+
400: 'Invalid Request',
355+
404: 'Not Found',
356+
429: 'Rate Limited',
357+
500: 'Infrastructure Issue',
358+
503: 'Infrastructure Issue',
359+
}
360+
361+
const retriableCode =
362+
Object.keys(RETRIABLE_MAP)
363+
.map(Number)
364+
.find(
365+
(code) => errorStatus === code || errorMessage.includes(String(code))
366+
)
367+
368+
if (retriableCode) {
369+
const reason = RETRIABLE_MAP[retriableCode] || 'Unknown Retriable Error'
367370
console.warn(
368-
`Model ${modelName} failed (${reason}${details}). Trying next model...`
371+
`Model ${modelName} failed (${reason}: ${errorMessage}). Trying next model...`
369372
)
370373
continue
371374
}

0 commit comments

Comments
 (0)