./stats.sh https://github.com/user/repo
Created
September 23, 2025 09:13
-
-
Save mr-karan/c7607b7cbaa81674df67f85dd2e5b307 to your computer and use it in GitHub Desktop.
Small bash script to fetch and display GitHub release download stats. Shows total downloads, release counts, and per-release breakdowns (sorted by date), with highlights for top releases.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
if [ $# -ne 1 ]; then | |
echo "Usage: $0 <github-repo-url>" | |
echo "Example: $0 https://github.com/mr-karan/logchef" | |
exit 1 | |
fi | |
REPO_URL=$1 | |
# Extract owner/repo from URL (assumes https://github.com/owner/repo format) | |
if [[ ! $REPO_URL =~ ^https://github\.com/([^/]+)/([^/]+)$ ]]; then | |
echo "Error: Invalid GitHub repository URL format" | |
exit 1 | |
fi | |
OWNER=${BASH_REMATCH[1]} | |
REPO=${BASH_REMATCH[2]} | |
echo "Fetching download stats for $OWNER/$REPO..." | |
echo | |
PAGE=1 | |
PER_PAGE=100 | |
TOTAL_DOWNLOADS=0 | |
TOTAL_RELEASES=0 | |
RELEASE_DATA="" | |
while true; do | |
API_URL="https://api.github.com/repos/$OWNER/$REPO/releases?page=$PAGE&per_page=$PER_PAGE" | |
RESPONSE=$(curl -s "$API_URL") | |
if [ $? -ne 0 ]; then | |
echo "Error: Failed to fetch data from GitHub API" | |
exit 1 | |
fi | |
# Check response type and handle errors | |
TYPE=$(echo "$RESPONSE" | jq -r 'type' 2>/dev/null || echo "invalid") | |
if [ "$TYPE" = "object" ]; then | |
ERROR=$(echo "$RESPONSE" | jq -r '.message // empty') | |
if [ -n "$ERROR" ]; then | |
echo "Error: $ERROR" | |
exit 1 | |
fi | |
elif [ "$TYPE" != "array" ]; then | |
echo "Error: Unexpected response format from GitHub API" | |
exit 1 | |
fi | |
RELEASE_COUNT=$(echo "$RESPONSE" | jq '. | length') | |
if [ "$RELEASE_COUNT" -eq 0 ]; then | |
break | |
fi | |
# Process each release | |
for i in $(seq 0 $((RELEASE_COUNT - 1))); do | |
RELEASE=$(echo "$RESPONSE" | jq ".[$i]") | |
TAG=$(echo "$RELEASE" | jq -r '.tag_name') | |
NAME=$(echo "$RELEASE" | jq -r '.name') | |
DATE=$(echo "$RELEASE" | jq -r '.published_at' | cut -d'T' -f1) | |
DOWNLOADS=$(echo "$RELEASE" | jq '[.assets | .[] | .download_count] | add // 0') | |
TOTAL_DOWNLOADS=$((TOTAL_DOWNLOADS + DOWNLOADS)) | |
RELEASE_DATA="$RELEASE_DATA$DATE|$TAG|$NAME|$DOWNLOADS\n" | |
done | |
TOTAL_RELEASES=$((TOTAL_RELEASES + RELEASE_COUNT)) | |
if [ "$RELEASE_COUNT" -lt "$PER_PAGE" ]; then | |
break | |
fi | |
PAGE=$((PAGE + 1)) | |
# Rate limiting | |
sleep 1 | |
done | |
# Get top 3 tags by downloads | |
TOP_TAGS=$(echo -e "$RELEASE_DATA" | sort -t'|' -k4 -nr | head -3 | cut -d'|' -f2) | |
# Sort releases by date descending | |
SORTED_DATA=$(echo -e "$RELEASE_DATA" | sort -r) | |
echo "==========================================" | |
echo "GitHub Download Statistics" | |
echo "==========================================" | |
echo "Repository: $OWNER/$REPO" | |
echo "Total Releases: $TOTAL_RELEASES" | |
echo "Total Downloads: $(printf "%'d" $TOTAL_DOWNLOADS)" | |
echo "* indicates releases with top 3 download counts" | |
echo | |
echo "Date | Tag | Name | Downloads" | |
echo "-----------|--------------|-------------------------|----------" | |
echo -e "$SORTED_DATA" | while IFS='|' read -r DATE TAG NAME DOWNLOADS; do | |
STAR="" | |
if echo "$TOP_TAGS" | grep -q "^$TAG$"; then | |
STAR=" *" | |
fi | |
printf "%-10s | %-12s | %-23s | %'d%s\n" "$DATE" "$TAG" "$NAME" "$DOWNLOADS" "$STAR" | |
done | |
echo "==========================================" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment