From d26f8a66e1583edfe6a8fd7886f86cbbae1a7e6c Mon Sep 17 00:00:00 2001 From: Hari Sekhon Date: Fri, 2 Feb 2024 20:48:03 +0000 Subject: [PATCH] updated github_api.sh --- github/github_api.sh | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/github/github_api.sh b/github/github_api.sh index b3db098f..1ac20786 100755 --- a/github/github_api.sh +++ b/github/github_api.sh @@ -34,6 +34,9 @@ Queries the GitHub.com API Automatically handles authentication via environment variables \$GITHUB_USERNAME / \$GITHUB_USER and \$GH_TOKEN / \$GITHUB_TOKEN / \$GITHUB_PASSWORD (password is deprecated) +Optional: \$GITHUB_USER - used for some replacement tokens, prevents having to search git remotes or query the API for it + \$GITHUB_HOST - used to point to self-hosts GitHub Enterprise servers + Can specify \$CURL_OPTS for options to pass to curl or provide them as arguments @@ -92,7 +95,7 @@ Examples: # shellcheck disable=SC2034 usage_args="/path []" -url_base="https://api.github.com" +url_base="https://${GITHUB_HOST:-api.github.com}" help_usage "$@" @@ -103,7 +106,9 @@ curl_api_opts "$@" url_path="$1" shift || : -url_path="${url_path//https:\/\/api.github.com}" +# false positive, this works +# shellcheck disable=SC2295 +url_path="${url_path##$url_base}" url_path="${url_path##/}" user="${GITHUB_USERNAME:-${GITHUB_USER:-}}"