shared_audits: allow GitHub's IP not permitted error

Co-authored-by: Mike McQuaid <mike@mikemcquaid.com>
This commit is contained in:
Alexander Bayandin 2023-08-25 13:58:51 +01:00 committed by Mike McQuaid
parent ae0f5637b7
commit 89d52f19a9
No known key found for this signature in database
GPG Key ID: 3338A31AFDB1D829

View File

@ -12,6 +12,10 @@ module SharedAudits
URL_TYPE_HOMEPAGE = "homepage URL" 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 module_function
def github_repo_data(user, repo) def github_repo_data(user, repo)
@ -21,6 +25,8 @@ module SharedAudits
@github_repo_data["#{user}/#{repo}"] @github_repo_data["#{user}/#{repo}"]
rescue GitHub::API::HTTPNotFoundError rescue GitHub::API::HTTPNotFoundError
nil nil
rescue GitHub::API::AuthenticationFailedError => e
raise unless e.message.match?(GITHUB_IP_ALLOWLIST_ERROR)
end end
def github_release_data(user, repo, tag) def github_release_data(user, repo, tag)
@ -32,6 +38,8 @@ module SharedAudits
@github_release_data[id] @github_release_data[id]
rescue GitHub::API::HTTPNotFoundError rescue GitHub::API::HTTPNotFoundError
nil nil
rescue GitHub::API::AuthenticationFailedError => e
raise unless e.message.match?(GITHUB_IP_ALLOWLIST_ERROR)
end end
def github_release(user, repo, tag, formula: nil, cask: nil) def github_release(user, repo, tag, formula: nil, cask: nil)