From 656a585ce1fa2998b9a6ccb8847d567deeb75221 Mon Sep 17 00:00:00 2001 From: Olivier Halligon Date: Thu, 19 Sep 2024 14:31:11 +0200 Subject: [PATCH] Fix logic of github_api to autodetect host --- bin/github_api | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bin/github_api b/bin/github_api index 72021cf2..6c1b065b 100755 --- a/bin/github_api +++ b/bin/github_api @@ -4,7 +4,7 @@ # # ENVIRONMENT VARIABLES: # GITHUB_TOKEN: Required. The GitHub token to use for authentication. -# GH_HOST: Optional. The GitHub host to use. We'll figure out the host from `BUILDKITE_*` env vars if not set. +# GH_HOST: Optional. The GitHub host to use. We'll figure out the host from `BUILDKITE_REPO` env var if not set. # # Usage: # github_api [curl-options] @@ -23,8 +23,8 @@ shift github_host=${GH_HOST:-} if [[ -z "${github_host}" ]]; then - if [[ -n "${BUILDKITE_PULL_REQUEST_REPO:-}" ]]; then - github_host=$(echo "$BUILDKITE_PULL_REQUEST_REPO" | awk -F[/:] '{print $4}') + if [[ "${BUILDKITE_REPO:-}" =~ ^(https?://|git@)([^/:]+)[:/] ]]; then + github_host="${BASH_REMATCH[2]}" else github_host=github.com fi