Skip to content

Commit

Permalink
utils/curl: include or use explicitly.
Browse files Browse the repository at this point in the history
Include or use `Utils::Curl` explicitly everywhere it is used.
  • Loading branch information
MikeMcQuaid committed Sep 4, 2023
1 parent 51889e7 commit 647f2e2
Show file tree
Hide file tree
Showing 13 changed files with 38 additions and 33 deletions.
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)

Check warning on line 131 in Library/Homebrew/system_config.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/system_config.rb#L131

Added line #L131 was not covered by tests

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: 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"

Check warning on line 68 in Library/Homebrew/utils/pypi.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/utils/pypi.rb#L68

Added line #L68 was not covered by tests

return unless status.success?

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}")

Check warning on line 61 in Library/Homebrew/utils/shared_audits.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/utils/shared_audits.rb#L61

Added line #L61 was not covered by tests
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(

Check warning on line 70 in Library/Homebrew/utils/shared_audits.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/utils/shared_audits.rb#L70

Added line #L70 was not covered by tests
"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)

Check warning on line 127 in Library/Homebrew/utils/shared_audits.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/utils/shared_audits.rb#L127

Added line #L127 was not covered by tests
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")

Check warning on line 139 in Library/Homebrew/utils/shared_audits.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/utils/shared_audits.rb#L139

Added line #L139 was not covered by tests
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")

Check warning on line 142 in Library/Homebrew/utils/shared_audits.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/utils/shared_audits.rb#L142

Added line #L142 was not covered by tests
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")

Check warning on line 35 in Library/Homebrew/utils/spdx.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/utils/spdx.rb#L34-L35

Added lines #L34 - L35 were not covered by tests
end

def parse_license_expression(license_expression)
Expand Down

0 comments on commit 647f2e2

Please sign in to comment.