Skip to content

Commit 15a5913

Browse files
committed
fix
1 parent 0fb44c7 commit 15a5913

File tree

1 file changed

+45
-22
lines changed

1 file changed

+45
-22
lines changed

.github/workflows/analytics.yaml

Lines changed: 45 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,40 +17,63 @@ jobs:
1717
run: |
1818
set -euo pipefail
1919
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')
20+
# Base search query; looks for import occurrences
21+
BASE_QUERY='@zetachain/protocol-contracts/contracts/zevm/GatewayZEVM.sol in:file'
2422
2523
PER_PAGE=100
26-
PAGE=1
2724
TMP=$(mktemp)
2825
trap 'rm -f "$TMP"' EXIT
2926
: > "$TMP"
3027
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}")
28+
fetch_repos() {
29+
local query="$1"
30+
local out="$2"
31+
local page=1
32+
while :; do
33+
local encoded
34+
encoded=$(jq -rn --arg q "$query" '$q|@uri')
35+
local resp
36+
resp=$(curl -sS \
37+
-H "Accept: application/vnd.github+json" \
38+
-H "X-GitHub-Api-Version: 2022-11-28" \
39+
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
40+
"https://api.github.com/search/code?q=${encoded}&per_page=${PER_PAGE}&page=${page}")
3741
38-
ITEMS_LEN=$(echo "$RESP" | jq '.items | length')
39-
if [ -z "$ITEMS_LEN" ] || [ "$ITEMS_LEN" -eq 0 ]; then
40-
break
41-
fi
42+
# If the API returns an error with a message, surface it for debugging
43+
local message
44+
message=$(echo "$resp" | jq -r '.message // empty')
45+
if [ -n "$message" ]; then
46+
echo "GitHub API message: $message" >&2
47+
fi
4248
43-
echo "$RESP" | jq -r '.items[].repository.html_url' >> "$TMP"
49+
local items_len
50+
items_len=$(echo "$resp" | jq '(.items // []) | length')
51+
if [ "$items_len" -eq 0 ]; then
52+
break
53+
fi
4454
45-
# Stop if this page returned fewer than PER_PAGE items
46-
if [ "$ITEMS_LEN" -lt "$PER_PAGE" ]; then
47-
break
48-
fi
55+
echo "$resp" | jq -r '.items[].repository.html_url' >> "$out"
4956
50-
PAGE=$((PAGE+1))
51-
done
57+
# Stop if fewer than PER_PAGE items returned
58+
if [ "$items_len" -lt "$PER_PAGE" ]; then
59+
break
60+
fi
5261
62+
page=$((page+1))
63+
done
64+
}
65+
66+
# Try excluding forks first
67+
fetch_repos "$BASE_QUERY fork:false" "$TMP"
5368
COUNT=$(sort -u "$TMP" | grep -c . || true)
69+
70+
# Fallback: include forks if excluding forks returns zero
71+
if [ "$COUNT" -eq 0 ]; then
72+
: > "$TMP"
73+
fetch_repos "$BASE_QUERY" "$TMP"
74+
COUNT=$(sort -u "$TMP" | grep -c . || true)
75+
fi
76+
5477
echo "Repositories using GatewayZEVM.sol: $COUNT"
5578
echo "count=$COUNT" >> "$GITHUB_OUTPUT"
5679

0 commit comments

Comments
 (0)