utils/github/api: avoid loading gh

This is causing errors in third-party taps after
Homebrew/homebrew-test-bot#934.

Fixes Homebrew/discussions#4546.
This commit is contained in:
Carlo Cabrera 2023-05-31 23:43:24 +08:00
parent a380aed887
commit faa58e6576
No known key found for this signature in database
GPG Key ID: C74D447FC549A1D0

View File

@ -126,7 +126,8 @@ module GitHub
# Gets the token from the GitHub CLI for github.com.
sig { returns(T.nilable(String)) }
def self.github_cli_token
env = { "PATH" => PATH.new(Formula["gh"].opt_bin, ENV.fetch("PATH")) }
# Avoid `Formula["gh"].opt_bin` so this method works even with `HOMEBREW_DISABLE_LOAD_FORMULA`.
env = { "PATH" => PATH.new(HOMEBREW_PREFIX/"opt/gh/bin", ENV.fetch("PATH")) }
gh_out, _, result = system_command "gh",
args: ["auth", "token", "--hostname", "github.com"],
env: env,