-
Notifications
You must be signed in to change notification settings - Fork 95
Download counts
To determine the amount of requested (not successfully completed) downloads for a given release, you need to go through the GitHub Releases API in a two step process.
Determine the GitHub Release "id" which is internal to GitHub's API. For every (git tagged) GitHub Release there is one corresponding Release ID. These are listed (in JSON format, and in correlation to the corresponding git tags) at
https://api.github.com/repos/MegaGlest/megaglest-source/releases
An imprecise and error-prone script which returns the release ID for a given git tag:
TAG="3.9.1"
wget -qO- https://api.github.com/repos/MegaGlest/megaglest-source/releases | grep -B1 '"tag_name": "'$TAG'"' | awk -F: '/"id":/ {print $2}' | tr -d ' ,'
Now that you know the internal Release ID, you can get download stats for each of the files ("assets") you uploaded. These are listed (in JSON format, and in correlation to their file names) at
https://api.github.com/repos/MegaGlest/megaglest-source/releases/RELEASE_ID/assets
(Replace RELEASE_ID by the Release ID you determined in step 1.)
An imprecise and error-prone script which returns the download statistics for a given Release ID:
RELEASE_ID="153116"
wget -qO- https://api.github.com/repos/MegaGlest/megaglest-source/releases/$RELEASE_ID/assets | awk -F: '/"(name|download_count)":/ {print $2}' | sed -e 's/^ *//' -e 's/,$//' -e ':a;/"$/{N;s/\n//;ba}' -e 's/,$//' | sort -nrk 2
An imprecise and error-prone script which returns the download stats for a given release tag:
TAG="3.9.1"
RELEASE_ID=`wget -qO- https://api.github.com/repos/MegaGlest/megaglest-source/releases | grep -B1 '"tag_name": "'$TAG'"' | awk -F: '/"id":/ {print $2}' | tr -d ' ,'`
wget -qO- https://api.github.com/repos/MegaGlest/megaglest-source/releases/$RELEASE_ID/assets | awk -F: '/"(name|download_count)":/ {print $2}' | sed -e 's/^ *//' -e 's/,$//' -e ':a;/"$/{N;s/\n//;ba}' -e 's/,$//' | sort -nrk 2
Finally, here's a script based on the approach above.
#!/bin/bash
ORGREPO=$1
TAG=$2
if [[ $1 == '' || $2 == '' ]]
then
echo 'Error: Incorrect number of parameters provided.' >&2
echo ''
echo 'Usage:'
echo ' '"`basename $0`"' <GITHUB_ORGANIZATION>/<GITHUB_REPOSITORY> <RELEASE_TAG>'
echo ''
echo 'Example:'
echo ' '"`basename $0`"' MegaGlest/megaglest-source 3.9.1'
exit 1
fi
RELEASE_ID=`wget -qO- "https://api.github.com/repos/${ORGREPO}/releases" | grep -B1 '"tag_name": "'$TAG'"' | awk -F: '/"id":/ {print $2}' | tr -d ' ,'`
wget -qO- "https://api.github.com/repos/${ORGREPO}/releases/${RELEASE_ID}/assets" | awk -F: '/"(name|download_count)":/ {print $2}' | sed -e 's/^ *//' -e 's/,$//' -e ':a;/"$/{N;s/\n//;ba}' -e 's/,$//' | sort -k2 -nr
Unless noted otherwise, all MegaGlest documentation is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.