Create Utils::Curl module and explicitly include it.

This commit is contained in:
Markus Reiter 2020-10-10 15:23:03 +02:00
parent 318091cccc
commit ff653571b1
5 changed files with 274 additions and 263 deletions

View File

@ -11,6 +11,8 @@ require "lock_file"
require "mechanize/version"
require "mechanize/http/content_disposition_parser"
require "utils/curl"
# @abstract Abstract superclass for all download strategies.
#
# @api private
@ -328,6 +330,8 @@ end
#
# @api public
class CurlDownloadStrategy < AbstractFileDownloadStrategy
include Utils::Curl
attr_reader :mirrors
def initialize(url, name, version, **meta)

View File

@ -1,15 +0,0 @@
# typed: strict
module SharedAudits
def github(user, repo)
end
def gitlab(user, repo)
end
def bitbucket(user, repo)
end
def curl_output(*args, secrets: [], **options)
end
end

View File

@ -3,6 +3,13 @@
require "open3"
module Utils
# Helper function for interacting with `curl`.
#
# @api private
module Curl
module_function
def curl_executable
@curl ||= [
ENV["HOMEBREW_CURL"],
@ -47,7 +54,9 @@ def curl_args(*extra_args, show_output: false, user_agent: :default)
args + extra_args
end
def curl_with_workarounds(*args, secrets: nil, print_stdout: nil, print_stderr: nil, verbose: nil, env: {}, **options)
def curl_with_workarounds(
*args, secrets: nil, print_stdout: nil, print_stderr: nil, verbose: nil, env: {}, **options
)
command_options = {
secrets: secrets,
print_stdout: print_stdout,
@ -118,7 +127,9 @@ def curl_download(*args, to: nil, partial: true, **options)
0
end
curl("--location", "--remote-time", "--continue-at", continue_at.to_s, "--output", destination, *args, **options)
curl(
"--location", "--remote-time", "--continue-at", continue_at.to_s, "--output", destination, *args, **options
)
end
def curl_output(*args, **options)
@ -259,3 +270,8 @@ end
def http_status_ok?(status)
(100..299).cover?(status.to_i)
end
end
end
# FIXME: Include `Utils::Curl` explicitly everywhere it is used.
include Utils::Curl # rubocop:disable Style/MixinUsage

View File

@ -7,6 +7,9 @@ require "utils/curl"
#
# @api private
module SharedAudits
include Utils::Curl
extend Utils::Curl
module_function
def github_repo_data(user, repo)

View File

@ -1,12 +1,15 @@
# typed: true
# frozen_string_literal: true
require "utils/curl"
require "utils/github"
# Helper module for updating SPDX license data.
#
# @api private
module SPDX
extend Utils::Curl
module_function
DATA_PATH = (HOMEBREW_DATA_PATH/"spdx").freeze