From c4e9a606539cbe80e5f5d58d74ff34923a1f4dfa Mon Sep 17 00:00:00 2001 From: Olivier Halligon Date: Thu, 19 Sep 2024 14:37:03 +0200 Subject: [PATCH] Fix logic of github_api to autodetect host (#127) * Fix logic of github_api to autodetect host * Add CHANGELOG entry --- CHANGELOG.md | 1 + bin/github_api | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 12432a80..b93442ea 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -43,6 +43,7 @@ _None._ ### Bug Fixes - Fix not working SARIF upload on non-PR branches [#124] +- Fix logic in our `github_api` helper to auto-detecting the GitHub host [#127] ### Internal Changes 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