-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathupdate-stats.sh
More file actions
executable file
·40 lines (29 loc) · 942 Bytes
/
update-stats.sh
File metadata and controls
executable file
·40 lines (29 loc) · 942 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/env bash
set -euo pipefail
JSON_FILE="apps.json"
if ! command -v jq &>/dev/null; then
echo "Error: jq is required. Install with: brew install jq"
exit 1
fi
tmp=$(mktemp)
cp "$JSON_FILE" "$tmp"
len=$(jq '.apps | length' "$tmp")
for ((i = 0; i < len; i++)); do
github=$(jq -r ".apps[$i].github" "$tmp")
repo=${github#https://github.com/}
name=$(jq -r ".apps[$i].name" "$tmp")
echo -n "Fetching $name ($repo)... "
response=$(curl -sf "https://api.github.com/repos/$repo" \
${GITHUB_TOKEN:+-H "Authorization: token $GITHUB_TOKEN"}) || {
echo "FAILED (rate limited or not found)"
continue
}
stars=$(echo "$response" | jq '.stargazers_count')
forks=$(echo "$response" | jq '.forks_count')
echo "★ $stars ⑂ $forks"
tmp2=$(mktemp)
jq ".apps[$i].stars = $stars | .apps[$i].forks = $forks" "$tmp" > "$tmp2"
mv "$tmp2" "$tmp"
done
mv "$tmp" "$JSON_FILE"
echo "Done. Updated $JSON_FILE"