diff --git a/Library/Homebrew/api.rb b/Library/Homebrew/api.rb index 6003c7dd5e..aa8f782652 100644 --- a/Library/Homebrew/api.rb +++ b/Library/Homebrew/api.rb @@ -1,4 +1,4 @@ -# typed: false +# typed: true # frozen_string_literal: true require "api/analytics" @@ -15,12 +15,10 @@ module Homebrew extend Cachable - module_function - HOMEBREW_CACHE_API = (HOMEBREW_CACHE/"api").freeze sig { params(endpoint: String).returns(Hash) } - def fetch(endpoint) + def self.fetch(endpoint) return cache[endpoint] if cache.present? && cache.key?(endpoint) api_url = "#{Homebrew::EnvConfig.api_domain}/#{endpoint}" @@ -37,8 +35,8 @@ module Homebrew raise ArgumentError, "Invalid JSON file: #{Tty.underline}#{api_url}#{Tty.reset}" end - sig { params(endpoint: String, target: Pathname).returns(Hash) } - def fetch_json_api_file(endpoint, target:) + sig { params(endpoint: String, target: Pathname).returns(T.any(Array, Hash)) } + def self.fetch_json_api_file(endpoint, target:) retry_count = 0 url = "#{Homebrew::EnvConfig.api_domain}/#{endpoint}" default_url = "#{HOMEBREW_API_DEFAULT_DOMAIN}/#{endpoint}" @@ -61,7 +59,7 @@ module Homebrew begin begin args = curl_args.dup - args.prepend("--time-cond", target) if target.exist? && !target.empty? + args.prepend("--time-cond", target.to_s) if target.exist? && !target.empty? unless skip_download ohai "Downloading #{url}" if $stdout.tty? # Disable retries here, we handle them ourselves below. @@ -97,7 +95,7 @@ module Homebrew end sig { params(filepath: String, repo: String, git_head: T.nilable(String)).returns(String) } - def fetch_file_source(filepath, repo:, git_head: nil) + def self.fetch_file_source(filepath, repo:, git_head: nil) git_head ||= "master" endpoint = "#{git_head}/#{filepath}" return cache[endpoint] if cache.present? && cache.key?(endpoint) @@ -110,7 +108,7 @@ module Homebrew end sig { params(json: Hash).returns(Hash) } - def merge_variations(json) + def self.merge_variations(json) if (bottle_tag = ::Utils::Bottles.tag.to_s.presence) && (variations = json["variations"].presence) && (variation = variations[bottle_tag].presence) diff --git a/Library/Homebrew/api/analytics.rb b/Library/Homebrew/api/analytics.rb index 87e57b1b0e..9609eb37c1 100644 --- a/Library/Homebrew/api/analytics.rb +++ b/Library/Homebrew/api/analytics.rb @@ -1,4 +1,4 @@ -# typed: false +# typed: true # frozen_string_literal: true module Homebrew diff --git a/Library/Homebrew/api/cask.rb b/Library/Homebrew/api/cask.rb index 4f7c4b8e36..fab01bb288 100644 --- a/Library/Homebrew/api/cask.rb +++ b/Library/Homebrew/api/cask.rb @@ -1,4 +1,4 @@ -# typed: false +# typed: true # frozen_string_literal: true module Homebrew diff --git a/Library/Homebrew/api/formula.rb b/Library/Homebrew/api/formula.rb index 48ebf47fdc..2ad31b137b 100644 --- a/Library/Homebrew/api/formula.rb +++ b/Library/Homebrew/api/formula.rb @@ -1,4 +1,4 @@ -# typed: false +# typed: true # frozen_string_literal: true module Homebrew diff --git a/Library/Homebrew/env_config.rbi b/Library/Homebrew/env_config.rbi new file mode 100644 index 0000000000..a822719989 --- /dev/null +++ b/Library/Homebrew/env_config.rbi @@ -0,0 +1,7 @@ +# typed: strict + +module Homebrew::EnvConfig + # This is necessary due to https://github.com/sorbet/sorbet/issues/6726 + sig { returns(String) } + def self.api_auto_update_secs; end +end