github: handle user opting out of github API in private_repo check

Today we get a sorbet error when the user opts out, because `json` is
`{}`, so `json["private"]` is `nil`.

Given this function is used to check whether to send analytics, I assume
we should default to treating the repo as a private repo.

Refs: 8ef7a9dbd4/Library/Homebrew/utils/github/api.rb (L276)
This commit is contained in:
Gibson Fahnestock 2025-09-11 10:31:46 +01:00
parent 610c67b715
commit e4ac3bfeed
No known key found for this signature in database
GPG Key ID: B01FBB92821C587A

View File

@ -119,10 +119,11 @@ module GitHub
API.open_rest(url, data:, scopes:)
end
# We default to private if we aren't sure or if the GitHub API is disabled.
sig { params(full_name: String).returns(T::Boolean) }
def self.private_repo?(full_name)
uri = url_to "repos", full_name
API.open_rest(uri) { |json| json["private"] }
API.open_rest(uri) { |json| json["private"].nil? || json["private"] }
end
def self.search_query_string(*main_params, **qualifiers)