Skip to content

Commit bd2c201

Browse files
committed
Support > 100 files in size-labeler.sh
This enhances the code to support getting more than 100 files from GitHub. (Written with the help of Gemini CLI.)
1 parent 0d15189 commit bd2c201

1 file changed

Lines changed: 31 additions & 23 deletions

File tree

dev_tools/ci/size-labeler.sh

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ declare -A LIMITS=(
3939
["${LABELS[4]}"]="$((2 ** 63 - 1))"
4040
)
4141

42-
# Note: these are Bash glob patterns and not regexes.
4342
declare -ar IGNORED=(
4443
"*_pb2.py"
4544
"*_pb2.pyi"
@@ -111,31 +110,40 @@ function api_call() {
111110

112111
function compute_changes() {
113112
local -r pr="$1"
114-
115-
local response
116-
local change_info
117113
local -r keys_filter='with_entries(select([.key] | inside(["changes", "filename"])))'
118-
response="$(api_call "pulls/${pr}/files?per_page=100")"
119-
change_info="$(jq_stdin "map(${keys_filter})" <<<"${response}")"
120-
121-
local files total_changes
122-
readarray -t files < <(jq_stdin -c '.[]' <<<"${change_info}")
123-
total_changes=0
124-
for file in "${files[@]}"; do
125-
local name changes
126-
name="$(jq_stdin -r '.filename' <<<"${file}")"
127-
for pattern in "${IGNORED[@]}"; do
128-
# shellcheck disable=SC2053 # Pattern must be left unquoted here.
129-
if [[ "$name" == ${pattern} ]]; then
130-
info "File $name ignored"
131-
continue 2
132-
fi
114+
115+
local page=1
116+
local total_changes=0
117+
while true; do
118+
local response
119+
response="$(api_call "pulls/${pr}/files?per_page=100&page=${page}")"
120+
121+
if [[ "$(jq_stdin '. | length' <<<"${response}")" -eq 0 ]]; then
122+
break
123+
fi
124+
125+
local change_info
126+
change_info="$(jq_stdin "map(${keys_filter})" <<<"${response}")"
127+
128+
local files
129+
readarray -t files < <(jq_stdin -c '.[]' <<<"${change_info}")
130+
for file in "${files[@]}"; do
131+
local name changes
132+
name="$(jq_stdin -r '.filename' <<<"${file}")"
133+
for pattern in "${IGNORED[@]}"; do
134+
# shellcheck disable=SC2053 # Need leave the pattern unquoted.
135+
if [[ "${name}" == ${pattern} ]]; then
136+
info "File ${name} ignored"
137+
continue 2
138+
fi
139+
done
140+
changes="$(jq_stdin -r '.changes' <<<"${file}")"
141+
info "File ${name} +-${changes}"
142+
total_changes="$((total_changes + changes))"
133143
done
134-
changes="$(jq_stdin -r '.changes' <<<"${file}")"
135-
info "File $name +-$changes"
136-
total_changes="$((total_changes + changes))"
144+
((page++))
137145
done
138-
echo "$total_changes"
146+
echo "${total_changes}"
139147
}
140148

141149
function get_size_label() {

0 commit comments

Comments
 (0)