utils/curl: include or use explicitly.
Include or use `Utils::Curl` explicitly everywhere it is used.
This commit is contained in:
		
							parent
							
								
									51889e7a08
								
							
						
					
					
						commit
						b7114651ac
					
				@ -4,6 +4,7 @@
 | 
			
		||||
require "cask/cache"
 | 
			
		||||
require "cask/cask"
 | 
			
		||||
require "uri"
 | 
			
		||||
require "utils/curl"
 | 
			
		||||
 | 
			
		||||
module Cask
 | 
			
		||||
  # Loads a cask from various sources.
 | 
			
		||||
@ -160,7 +161,7 @@ module Cask
 | 
			
		||||
 | 
			
		||||
        begin
 | 
			
		||||
          ohai "Downloading #{url}"
 | 
			
		||||
          curl_download url, to: path
 | 
			
		||||
          ::Utils::Curl.curl_download url, to: path
 | 
			
		||||
        rescue ErrorDuringExecution
 | 
			
		||||
          raise CaskUnavailableError.new(token, "Failed to download #{Formatter.url(url)}.")
 | 
			
		||||
        end
 | 
			
		||||
 | 
			
		||||
@ -11,6 +11,7 @@ module Homebrew
 | 
			
		||||
  # @api private
 | 
			
		||||
  class FormulaAuditor
 | 
			
		||||
    include FormulaCellarChecks
 | 
			
		||||
    include Utils::Curl
 | 
			
		||||
 | 
			
		||||
    attr_reader :formula, :text, :problems, :new_formula_problems
 | 
			
		||||
 | 
			
		||||
@ -537,12 +538,14 @@ module Homebrew
 | 
			
		||||
        spec.using == :homebrew_curl
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      if (http_content_problem = curl_check_http_content(homepage,
 | 
			
		||||
                                                         SharedAudits::URL_TYPE_HOMEPAGE,
 | 
			
		||||
                                                         user_agents:       [:browser, :default],
 | 
			
		||||
                                                         check_content:     true,
 | 
			
		||||
                                                         strict:            @strict,
 | 
			
		||||
                                                         use_homebrew_curl: use_homebrew_curl))
 | 
			
		||||
      if (http_content_problem = curl_check_http_content(
 | 
			
		||||
        homepage,
 | 
			
		||||
        SharedAudits::URL_TYPE_HOMEPAGE,
 | 
			
		||||
        user_agents:       [:browser, :default],
 | 
			
		||||
        check_content:     true,
 | 
			
		||||
        strict:            @strict,
 | 
			
		||||
        use_homebrew_curl: use_homebrew_curl,
 | 
			
		||||
      ))
 | 
			
		||||
        problem http_content_problem
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
@ -6,6 +6,7 @@ require "extend/cachable"
 | 
			
		||||
require "tab"
 | 
			
		||||
require "utils/bottles"
 | 
			
		||||
require "service"
 | 
			
		||||
require "utils/curl"
 | 
			
		||||
 | 
			
		||||
require "active_support/core_ext/hash/deep_transform_values"
 | 
			
		||||
 | 
			
		||||
@ -591,7 +592,7 @@ module Formulary
 | 
			
		||||
      end
 | 
			
		||||
      HOMEBREW_CACHE_FORMULA.mkpath
 | 
			
		||||
      FileUtils.rm_f(path)
 | 
			
		||||
      curl_download url, to: path
 | 
			
		||||
      Utils::Curl.curl_download url, to: path
 | 
			
		||||
      super
 | 
			
		||||
    rescue MethodDeprecatedError => e
 | 
			
		||||
      if (match_data = url.match(%r{github.com/(?<user>[\w-]+)/(?<repo>[\w-]+)/}).presence)
 | 
			
		||||
 | 
			
		||||
@ -9,7 +9,6 @@ require "json"
 | 
			
		||||
# @api private
 | 
			
		||||
class GitHubReleases
 | 
			
		||||
  include Context
 | 
			
		||||
  include Utils::Curl
 | 
			
		||||
 | 
			
		||||
  URL_REGEX = %r{https://github\.com/([\w-]+)/([\w-]+)?/releases/download/(.+)}.freeze
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -123,10 +123,12 @@ module Homebrew
 | 
			
		||||
          raise HomebrewCurlDownloadStrategyError, url if
 | 
			
		||||
            strategy <= HomebrewCurlDownloadStrategy && !Formula["curl"].any_version_installed?
 | 
			
		||||
 | 
			
		||||
          if (http_content_problem = curl_check_http_content(url,
 | 
			
		||||
                                                             "source URL",
 | 
			
		||||
                                                             specs:             specs,
 | 
			
		||||
                                                             use_homebrew_curl: @use_homebrew_curl))
 | 
			
		||||
          if (http_content_problem = Utils::Curl.curl_check_http_content(
 | 
			
		||||
            url,
 | 
			
		||||
            "source URL",
 | 
			
		||||
            specs:             specs,
 | 
			
		||||
            use_homebrew_curl: @use_homebrew_curl,
 | 
			
		||||
          ))
 | 
			
		||||
            problem http_content_problem
 | 
			
		||||
          end
 | 
			
		||||
        elsif strategy <= GitDownloadStrategy
 | 
			
		||||
 | 
			
		||||
@ -128,11 +128,11 @@ module SystemConfig
 | 
			
		||||
 | 
			
		||||
    sig { returns(String) }
 | 
			
		||||
    def describe_curl
 | 
			
		||||
      out, = system_command(curl_executable, args: ["--version"], verbose: false)
 | 
			
		||||
      out, = system_command(Utils::Curl.curl_executable, args: ["--version"], verbose: false)
 | 
			
		||||
 | 
			
		||||
      match_data = /^curl (?<curl_version>[\d.]+)/.match(out)
 | 
			
		||||
      if match_data
 | 
			
		||||
        "#{match_data[:curl_version]} => #{curl_path}"
 | 
			
		||||
        "#{match_data[:curl_version]} => #{Utils::Curl.curl_path}"
 | 
			
		||||
      else
 | 
			
		||||
        "N/A"
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
@ -167,7 +167,7 @@ RSpec.configure do |config|
 | 
			
		||||
 | 
			
		||||
  config.before(:each, :needs_homebrew_curl) do
 | 
			
		||||
    ENV["HOMEBREW_CURL"] = HOMEBREW_BREWED_CURL_PATH
 | 
			
		||||
    skip "A `curl` with TLS 1.3 support is required." unless curl_supports_tls13?
 | 
			
		||||
    skip "A `curl` with TLS 1.3 support is required." unless Utils::Curl.curl_supports_tls13?
 | 
			
		||||
  rescue FormulaUnavailableError
 | 
			
		||||
    skip "No `curl` formula is available."
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
@ -3,6 +3,8 @@
 | 
			
		||||
require "utils/curl"
 | 
			
		||||
 | 
			
		||||
describe "Utils::Curl" do
 | 
			
		||||
  include Utils::Curl
 | 
			
		||||
 | 
			
		||||
  let(:details) do
 | 
			
		||||
    details = {
 | 
			
		||||
      normal:     {},
 | 
			
		||||
 | 
			
		||||
@ -609,6 +609,3 @@ module Utils
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
# FIXME: Include `Utils::Curl` explicitly everywhere it is used.
 | 
			
		||||
include Utils::Curl # rubocop:disable Style/MixinUsage
 | 
			
		||||
 | 
			
		||||
@ -251,7 +251,7 @@ module GitHub
 | 
			
		||||
 | 
			
		||||
        args += ["--dump-header", T.must(headers_tmpfile.path)]
 | 
			
		||||
 | 
			
		||||
        output, errors, status = curl_output("--location", url.to_s, *args, secrets: [token])
 | 
			
		||||
        output, errors, status = Utils::Curl.curl_output("--location", url.to_s, *args, secrets: [token])
 | 
			
		||||
        output, _, http_code = output.rpartition("\n")
 | 
			
		||||
        output, _, http_code = output.rpartition("\n") if http_code == "000"
 | 
			
		||||
        headers = headers_tmpfile.read
 | 
			
		||||
 | 
			
		||||
@ -65,7 +65,7 @@ module PyPI
 | 
			
		||||
      else
 | 
			
		||||
        "https://pypi.org/pypi/#{name}/json"
 | 
			
		||||
      end
 | 
			
		||||
      out, _, status = curl_output metadata_url, "--location", "--fail"
 | 
			
		||||
      out, _, status = Utils::Curl.curl_output metadata_url, "--location", "--fail"
 | 
			
		||||
 | 
			
		||||
      return unless status.success?
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -16,7 +16,8 @@ module Repology
 | 
			
		||||
    last_package_in_response += "/" if last_package_in_response.present?
 | 
			
		||||
    url = "https://repology.org/api/v1/projects/#{last_package_in_response}?inrepo=#{repository}&outdated=1"
 | 
			
		||||
 | 
			
		||||
    output, errors, = curl_output(url.to_s, "--silent", use_homebrew_curl: !curl_supports_tls13?)
 | 
			
		||||
    output, errors, = Utils::Curl.curl_output(url.to_s, "--silent",
 | 
			
		||||
                                              use_homebrew_curl: !Utils::Curl.curl_supports_tls13?)
 | 
			
		||||
    JSON.parse(output)
 | 
			
		||||
  rescue
 | 
			
		||||
    if Homebrew::EnvConfig.developer?
 | 
			
		||||
@ -31,7 +32,8 @@ module Repology
 | 
			
		||||
  def self.single_package_query(name, repository:)
 | 
			
		||||
    url = "https://repology.org/api/v1/project/#{name}"
 | 
			
		||||
 | 
			
		||||
    output, errors, = curl_output("--location", "--silent", url.to_s, use_homebrew_curl: !curl_supports_tls13?)
 | 
			
		||||
    output, errors, = Utils::Curl.curl_output("--location", "--silent", url.to_s,
 | 
			
		||||
                                              use_homebrew_curl: !Utils::Curl.curl_supports_tls13?)
 | 
			
		||||
 | 
			
		||||
    data = JSON.parse(output)
 | 
			
		||||
    { name => data }
 | 
			
		||||
 | 
			
		||||
@ -2,14 +2,12 @@
 | 
			
		||||
# frozen_string_literal: true
 | 
			
		||||
 | 
			
		||||
require "utils/curl"
 | 
			
		||||
require "utils/github/api"
 | 
			
		||||
 | 
			
		||||
# Auditing functions for rules common to both casks and formulae.
 | 
			
		||||
#
 | 
			
		||||
# @api private
 | 
			
		||||
module SharedAudits
 | 
			
		||||
  include Utils::Curl
 | 
			
		||||
  extend Utils::Curl
 | 
			
		||||
 | 
			
		||||
  URL_TYPE_HOMEPAGE = "homepage URL"
 | 
			
		||||
 | 
			
		||||
  module_function
 | 
			
		||||
@ -60,7 +58,7 @@ module SharedAudits
 | 
			
		||||
  def gitlab_repo_data(user, repo)
 | 
			
		||||
    @gitlab_repo_data ||= {}
 | 
			
		||||
    @gitlab_repo_data["#{user}/#{repo}"] ||= begin
 | 
			
		||||
      out, _, status = curl_output("https://gitlab.com/api/v4/projects/#{user}%2F#{repo}")
 | 
			
		||||
      out, _, status = Utils::Curl.curl_output("https://gitlab.com/api/v4/projects/#{user}%2F#{repo}")
 | 
			
		||||
      JSON.parse(out) if status.success?
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
@ -69,7 +67,7 @@ module SharedAudits
 | 
			
		||||
    id = "#{user}/#{repo}/#{tag}"
 | 
			
		||||
    @gitlab_release_data ||= {}
 | 
			
		||||
    @gitlab_release_data[id] ||= begin
 | 
			
		||||
      out, _, status = curl_output(
 | 
			
		||||
      out, _, status = Utils::Curl.curl_output(
 | 
			
		||||
        "https://gitlab.com/api/v4/projects/#{user}%2F#{repo}/releases/#{tag}", "--fail"
 | 
			
		||||
      )
 | 
			
		||||
      JSON.parse(out) if status.success?
 | 
			
		||||
@ -126,7 +124,7 @@ module SharedAudits
 | 
			
		||||
 | 
			
		||||
  def bitbucket(user, repo)
 | 
			
		||||
    api_url = "https://api.bitbucket.org/2.0/repositories/#{user}/#{repo}"
 | 
			
		||||
    out, _, status= curl_output("--request", "GET", api_url)
 | 
			
		||||
    out, _, status = Utils::Curl.curl_output("--request", "GET", api_url)
 | 
			
		||||
    return unless status.success?
 | 
			
		||||
 | 
			
		||||
    metadata = JSON.parse(out)
 | 
			
		||||
@ -138,10 +136,10 @@ module SharedAudits
 | 
			
		||||
 | 
			
		||||
    return "Bitbucket repository too new (<30 days old)" if Date.parse(metadata["created_on"]) >= (Date.today - 30)
 | 
			
		||||
 | 
			
		||||
    forks_out, _, forks_status= curl_output("--request", "GET", "#{api_url}/forks")
 | 
			
		||||
    forks_out, _, forks_status = Utils::Curl.curl_output("--request", "GET", "#{api_url}/forks")
 | 
			
		||||
    return unless forks_status.success?
 | 
			
		||||
 | 
			
		||||
    watcher_out, _, watcher_status= curl_output("--request", "GET", "#{api_url}/watchers")
 | 
			
		||||
    watcher_out, _, watcher_status = Utils::Curl.curl_output("--request", "GET", "#{api_url}/watchers")
 | 
			
		||||
    return unless watcher_status.success?
 | 
			
		||||
 | 
			
		||||
    forks_metadata = JSON.parse(forks_out)
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										5
									
								
								Library/Homebrew/utils/shared_audits.rbi
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								Library/Homebrew/utils/shared_audits.rbi
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,5 @@
 | 
			
		||||
# typed: strict
 | 
			
		||||
 | 
			
		||||
module SharedAudits
 | 
			
		||||
  include ::Kernel
 | 
			
		||||
end
 | 
			
		||||
@ -8,9 +8,6 @@ require "utils/github"
 | 
			
		||||
#
 | 
			
		||||
# @api private
 | 
			
		||||
module SPDX
 | 
			
		||||
  include Utils::Curl
 | 
			
		||||
  extend Utils::Curl
 | 
			
		||||
 | 
			
		||||
  module_function
 | 
			
		||||
 | 
			
		||||
  DATA_PATH = (HOMEBREW_DATA_PATH/"spdx").freeze
 | 
			
		||||
@ -34,8 +31,8 @@ module SPDX
 | 
			
		||||
 | 
			
		||||
  def download_latest_license_data!(to: DATA_PATH)
 | 
			
		||||
    data_url = "https://raw.githubusercontent.com/spdx/license-list-data/#{latest_tag}/json/"
 | 
			
		||||
    curl_download("#{data_url}licenses.json", to: to/"spdx_licenses.json")
 | 
			
		||||
    curl_download("#{data_url}exceptions.json", to: to/"spdx_exceptions.json")
 | 
			
		||||
    Utils::Curl.curl_download("#{data_url}licenses.json", to: to/"spdx_licenses.json")
 | 
			
		||||
    Utils::Curl.curl_download("#{data_url}exceptions.json", to: to/"spdx_exceptions.json")
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def parse_license_expression(license_expression)
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user