Skip to content

Commit 0fb44c7

Browse files
committed
loop through pages
1 parent 80f4c2c commit 0fb44c7

File tree

1 file changed

+36
-4
lines changed

1 file changed

+36
-4
lines changed

.github/workflows/analytics.yaml

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,42 @@ jobs:
1515
- name: Count repos using GitHub Code Search
1616
id: count
1717
run: |
18-
COUNT=$(curl -s -H "Accept: application/vnd.github+json" \
19-
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
20-
"https://api.github.com/search/code?q=@zetachain/protocol-contracts/contracts/zevm/GatewayZEVM.sol+in:file" \
21-
| jq -r '.items[].repository.html_url' | sort -u | wc -l)
18+
set -euo pipefail
19+
20+
# Build search query; include fork:false to exclude forks (remove if undesired)
21+
QUERY='@zetachain/protocol-contracts/contracts/zevm/GatewayZEVM.sol in:file fork:false'
22+
# URL-encode the query using jq
23+
ENCODED_QUERY=$(jq -rn --arg q "$QUERY" '$q|@uri')
24+
25+
PER_PAGE=100
26+
PAGE=1
27+
TMP=$(mktemp)
28+
trap 'rm -f "$TMP"' EXIT
29+
: > "$TMP"
30+
31+
while :; do
32+
RESP=$(curl -sS \
33+
-H "Accept: application/vnd.github+json" \
34+
-H "X-GitHub-Api-Version: 2022-11-28" \
35+
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
36+
"https://api.github.com/search/code?q=${ENCODED_QUERY}&per_page=${PER_PAGE}&page=${PAGE}")
37+
38+
ITEMS_LEN=$(echo "$RESP" | jq '.items | length')
39+
if [ -z "$ITEMS_LEN" ] || [ "$ITEMS_LEN" -eq 0 ]; then
40+
break
41+
fi
42+
43+
echo "$RESP" | jq -r '.items[].repository.html_url' >> "$TMP"
44+
45+
# Stop if this page returned fewer than PER_PAGE items
46+
if [ "$ITEMS_LEN" -lt "$PER_PAGE" ]; then
47+
break
48+
fi
49+
50+
PAGE=$((PAGE+1))
51+
done
52+
53+
COUNT=$(sort -u "$TMP" | grep -c . || true)
2254
echo "Repositories using GatewayZEVM.sol: $COUNT"
2355
echo "count=$COUNT" >> "$GITHUB_OUTPUT"
2456

0 commit comments

Comments
 (0)