From 45378f35e2528950790e7e8eefc1cc3295cc5bdc Mon Sep 17 00:00:00 2001 From: Alexander Bayandin Date: Sat, 26 Aug 2023 17:16:43 +0100 Subject: [PATCH] get_repo_license: ignore ip allowlist error --- Library/Homebrew/utils/github.rb | 2 ++ Library/Homebrew/utils/github/api.rb | 4 ++++ Library/Homebrew/utils/shared_audits.rb | 8 ++------ 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/Library/Homebrew/utils/github.rb b/Library/Homebrew/utils/github.rb index b0b77393ee..d5a3d2c4ca 100644 --- a/Library/Homebrew/utils/github.rb +++ b/Library/Homebrew/utils/github.rb @@ -504,6 +504,8 @@ module GitHub response["license"]["spdx_id"] rescue API::HTTPNotFoundError nil + rescue API::AuthenticationFailedError => e + raise unless e.message.match?(API::GITHUB_IP_ALLOWLIST_ERROR) end def self.pull_request_title_regex(name, version = nil) diff --git a/Library/Homebrew/utils/github/api.rb b/Library/Homebrew/utils/github/api.rb index 151fd73aa4..88423561a2 100644 --- a/Library/Homebrew/utils/github/api.rb +++ b/Library/Homebrew/utils/github/api.rb @@ -60,6 +60,10 @@ module GitHub end end + GITHUB_IP_ALLOWLIST_ERROR = Regexp.new("Although you appear to have the correct authorization credentials, " \ + "the `(.+)` organization has an IP allow list enabled, " \ + "and your IP address is not permitted to access this resource").freeze + NO_CREDENTIALS_MESSAGE = <<~MESSAGE No GitHub credentials found in macOS Keychain, GitHub CLI or the environment. #{GitHub.pat_blurb} diff --git a/Library/Homebrew/utils/shared_audits.rb b/Library/Homebrew/utils/shared_audits.rb index b47e3060b0..c192d59ec7 100644 --- a/Library/Homebrew/utils/shared_audits.rb +++ b/Library/Homebrew/utils/shared_audits.rb @@ -12,10 +12,6 @@ module SharedAudits URL_TYPE_HOMEPAGE = "homepage URL" - GITHUB_IP_ALLOWLIST_ERROR = Regexp.new("Although you appear to have the correct authorization credentials, " \ - "the `(.+)` organization has an IP allow list enabled, " \ - "and your IP address is not permitted to access this resource").freeze - module_function def github_repo_data(user, repo) @@ -26,7 +22,7 @@ module SharedAudits rescue GitHub::API::HTTPNotFoundError nil rescue GitHub::API::AuthenticationFailedError => e - raise unless e.message.match?(GITHUB_IP_ALLOWLIST_ERROR) + raise unless e.message.match?(GitHub::API::GITHUB_IP_ALLOWLIST_ERROR) end def github_release_data(user, repo, tag) @@ -39,7 +35,7 @@ module SharedAudits rescue GitHub::API::HTTPNotFoundError nil rescue GitHub::API::AuthenticationFailedError => e - raise unless e.message.match?(GITHUB_IP_ALLOWLIST_ERROR) + raise unless e.message.match?(GitHub::API::GITHUB_IP_ALLOWLIST_ERROR) end def github_release(user, repo, tag, formula: nil, cask: nil)