-
-
Notifications
You must be signed in to change notification settings - Fork 699
Expand file tree
/
Copy pathupdate-github-data.sh
More file actions
executable file
·88 lines (72 loc) · 2.27 KB
/
update-github-data.sh
File metadata and controls
executable file
·88 lines (72 loc) · 2.27 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/bin/bash
# Script to fetch sponsors and contributors data from GitHub using gh CLI
# Usage: ./update-github-data.sh
set -e
REPO_OWNER="nunocoracao"
REPO_NAME="blowfish"
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
DATA_DIR="$SCRIPT_DIR/data"
# Ensure data directory exists
mkdir -p "$DATA_DIR"
echo "Fetching sponsors..."
# Fetch sponsors via GraphQL API
# Note: This requires the user to have GitHub Sponsors enabled
gh api graphql -f query='
query {
user(login: "'"$REPO_OWNER"'") {
sponsorshipsAsMaintainer(first: 100, activeOnly: true) {
nodes {
sponsorEntity {
... on User {
login
avatarUrl
url
}
... on Organization {
login
avatarUrl
url
}
}
}
}
}
}
' --jq '[.data.user.sponsorshipsAsMaintainer.nodes[] | {
username: .sponsorEntity.login,
avatar_url: (.sponsorEntity.avatarUrl + "&s=128"),
profile_url: .sponsorEntity.url
}]' > "$DATA_DIR/sponsors.json" 2>/dev/null || echo "[]" > "$DATA_DIR/sponsors.json"
sponsor_count=$(jq length "$DATA_DIR/sponsors.json")
echo "Found $sponsor_count sponsors"
echo "Fetching contributors..."
# Fetch all contributors via REST API (paginated)
all_contributors="[]"
page=1
while true; do
response=$(gh api "repos/$REPO_OWNER/$REPO_NAME/contributors?per_page=100&page=$page" \
--jq '[.[] | {
username: .login,
avatar_url: (.avatar_url + "&s=80"),
profile_url: .html_url,
contributions: .contributions
}]' 2>/dev/null || echo "[]")
if [ "$response" = "[]" ] || [ -z "$response" ]; then
break
fi
all_contributors=$(echo "$all_contributors" "$response" | jq -s 'add')
page=$((page + 1))
# Progress indicator
current_count=$(echo "$all_contributors" | jq length)
echo " Fetched $current_count contributors so far..."
done
# Sort by contributions (descending) and save
echo "$all_contributors" | jq 'sort_by(-.contributions)' > "$DATA_DIR/contributors.json"
contributor_count=$(jq length "$DATA_DIR/contributors.json")
echo "Found $contributor_count contributors"
echo ""
echo "Data saved to:"
echo " - $DATA_DIR/sponsors.json ($sponsor_count sponsors)"
echo " - $DATA_DIR/contributors.json ($contributor_count contributors)"
echo ""
echo "Done!"