Skip to content

Instantly share code, notes, and snippets.

@generalmimon
Last active September 9, 2024 18:45
Show Gist options
  • Save generalmimon/e983ec9c31481cdb835fe00908bcc69d to your computer and use it in GitHub Desktop.
Save generalmimon/e983ec9c31481cdb835fe00908bcc69d to your computer and use it in GitHub Desktop.
Show Kaitai Struct compiler (https://kaitai.io/) download stats from GitHub Releases per individual files
#!/usr/bin/env sh
# SPDX-FileCopyrightText: 2021-2024 Petr Pucil <[email protected]>
#
# SPDX-License-Identifier: CC0-1.0
# A shell script to show Kaitai Struct <https://kaitai.io/> compiler download
# stats from GitHub Releases per individual files.
#
# Make sure to set the `GH_AUTH_TOKEN` environment variable to a valid GitHub
# fine-grained personal access token (see
# https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens#creating-a-fine-grained-personal-access-token)
# before running this script. You don't need to select any repositories or
# permissions, because we only need read-only access to a public repository. For
# example, this Bash invocation prompts you for this token:
# $ ( read -r -s -p 'Token: ' GH_AUTH_TOKEN && echo && export GH_AUTH_TOKEN && ./ksc-release-download-stats.sh )
#
# Requires <https://stedolan.github.io/jq> and <https://curl.se> to work.
if [ -z "$GH_AUTH_TOKEN" ]; then
echo 'GH_AUTH_TOKEN environment variable is not set!' >&2
exit 1
fi
if ! response=$(curl \
--fail-with-body -sSL \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${GH_AUTH_TOKEN}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
'https://api.github.com/repos/kaitai-io/kaitai_struct_compiler/releases')
then
echo 'The GitHub REST API request failed!' >&2
echo 'Response received:' >&2
printf '%s\n' "$response" >&2
exit 1
fi
printf '%s\n' "$response" | jq 'map({name, assets: .assets | map({name, download_count})})'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment