Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

utils/curl: include or use explicitly. #15940

Merged
merged 1 commit into from
Sep 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Library/Homebrew/cask/cask_loader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
require "cask/cache"
require "cask/cask"
require "uri"
require "utils/curl"

module Cask
# Loads a cask from various sources.
Expand Down Expand Up @@ -160,7 +161,7 @@ def load(config:)

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
Expand Down
15 changes: 9 additions & 6 deletions Library/Homebrew/formula_auditor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ module Homebrew
# @api private
class FormulaAuditor
include FormulaCellarChecks
include Utils::Curl

attr_reader :formula, :text, :problems, :new_formula_problems

Expand Down Expand Up @@ -537,12 +538,14 @@ def audit_homepage
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
Expand Down
3 changes: 2 additions & 1 deletion Library/Homebrew/formulary.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
require "tab"
require "utils/bottles"
require "service"
require "utils/curl"

require "active_support/core_ext/hash/deep_transform_values"

Expand Down Expand Up @@ -591,7 +592,7 @@ def load_file(flags:, ignore_errors:)
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)
Expand Down
1 change: 0 additions & 1 deletion Library/Homebrew/github_releases.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
# @api private
class GitHubReleases
include Context
include Utils::Curl

URL_REGEX = %r{https://github\.com/([\w-]+)/([\w-]+)?/releases/download/(.+)}.freeze

Expand Down
10 changes: 6 additions & 4 deletions Library/Homebrew/resource_auditor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,12 @@ def audit_urls
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
Expand Down
4 changes: 2 additions & 2 deletions Library/Homebrew/system_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,11 @@ def describe_git

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
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/test/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@

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
Expand Down
2 changes: 2 additions & 0 deletions Library/Homebrew/test/utils/curl_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
require "utils/curl"

describe "Utils::Curl" do
include Utils::Curl

let(:details) do
details = {
normal: {},
Expand Down
3 changes: 0 additions & 3 deletions Library/Homebrew/utils/curl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,3 @@ def parse_curl_response(response_text)
end
end
end

# FIXME: Include `Utils::Curl` explicitly everywhere it is used.
include Utils::Curl # rubocop:disable Style/MixinUsage
2 changes: 1 addition & 1 deletion Library/Homebrew/utils/github/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ def self.open_rest(

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
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/utils/pypi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def pypi_info(new_version: nil)
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?

Expand Down
6 changes: 4 additions & 2 deletions Library/Homebrew/utils/repology.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ def self.query_api(last_package_in_response = "", repository:)
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?
Expand All @@ -31,7 +32,8 @@ def self.query_api(last_package_in_response = "", repository:)
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 }
Expand Down
14 changes: 6 additions & 8 deletions Library/Homebrew/utils/shared_audits.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -60,7 +58,7 @@ def github_release(user, repo, tag, formula: nil, cask: nil)
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
Expand All @@ -69,7 +67,7 @@ def gitlab_release_data(user, repo, tag)
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?
Expand Down Expand Up @@ -126,7 +124,7 @@ def gitlab(user, repo)

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)
Expand All @@ -138,10 +136,10 @@ def bitbucket(user, repo)

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)
Expand Down
5 changes: 5 additions & 0 deletions Library/Homebrew/utils/shared_audits.rbi
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# typed: strict

module SharedAudits
include ::Kernel
end
7 changes: 2 additions & 5 deletions Library/Homebrew/utils/spdx.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@
#
# @api private
module SPDX
include Utils::Curl
extend Utils::Curl

module_function

DATA_PATH = (HOMEBREW_DATA_PATH/"spdx").freeze
Expand All @@ -34,8 +31,8 @@ def latest_tag

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)
Expand Down