Updated GH_TOKEN usage (#1688)

This commit is contained in:
Nolan Rosen
2022-08-21 16:31:54 -04:00
committed by GitHub
parent de43778eb9
commit 4f8104737e
2 changed files with 22 additions and 17 deletions

View File

@@ -1,5 +1,23 @@
#!/bin/bash
function get_from_gh() {
if [[ "${GH_TOKEN:-}" ]]; then
# User has provided a Personal Access Token to mitigate rate-limiting issues
if [[ -z "${oAuthScopes}" ]]; then
oAuthScopes=$(curl -s -H "Authorization: token $GH_TOKEN" https://api.github.com/users/codertocat -I | grep x-oauth-scopes)
fi
if [[ ! "$oAuthScopes" =~ ^x-oauth-scopes:[[:space:]]*$ ]]; then
# Don't use what you don't have to...
log "ERROR: GH_TOKEN has permissions it doesn't need. Recreate or update this personal access token and disable ALL scopes."
exit 1
else
echo $(curl -fsSL -H "Authorization: token $GH_TOKEN" ${@:2} $1)
fi
else
echo $(curl -fsSL ${@:2} $1)
fi
}
function join_by() {
local d=$1
shift
@@ -291,7 +309,7 @@ function checkSum() {
# Get distro
distro=$(getDistro)
if [ "${distro}" == "debian" ] && sha1sum -c "${sum_file}" --status 2> /dev/null; then
return 0
elif [ "${distro}" == "ubuntu" ] && sha1sum -c "${sum_file}" --status 2> /dev/null; then