Removed use_homebrew_curl? for resources

This commit is contained in:
Mohammad Zain Abbas 2022-08-11 21:25:24 +02:00
parent c111a5bc9d
commit 54c9338ed4
2 changed files with 3 additions and 34 deletions

View File

@ -583,7 +583,7 @@ resource: false)
# livecheck should fetch a URL using brewed curl if the formula/resource/cask # livecheck should fetch a URL using brewed curl if the formula/resource/cask
# contains a `stable`/`url` or `head` URL `using: :homebrew_curl` that # contains a `stable`/`url` or `head` URL `using: :homebrew_curl` that
# shares the same root domain. # shares the same root domain.
sig { params(package_or_resource: T.any(Formula, Cask::Cask, Resource), url: String).returns(T::Boolean) } sig { params(package_or_resource: T.any(Formula, Cask::Cask), url: String).returns(T::Boolean) }
def use_homebrew_curl?(package_or_resource, url) def use_homebrew_curl?(package_or_resource, url)
url_root_domain = Addressable::URI.parse(url)&.domain url_root_domain = Addressable::URI.parse(url)&.domain
return false if url_root_domain.blank? return false if url_root_domain.blank?
@ -602,11 +602,6 @@ resource: false)
when Cask::Cask when Cask::Cask
return false unless package_or_resource.url.using == :homebrew_curl return false unless package_or_resource.url.using == :homebrew_curl
domain = Addressable::URI.parse(package_or_resource.url.to_s)&.domain
homebrew_curl_root_domains << domain if domain.present?
when Resource
return false unless package_or_resource.url == :homebrew_curl
domain = Addressable::URI.parse(package_or_resource.url.to_s)&.domain domain = Addressable::URI.parse(package_or_resource.url.to_s)&.domain
homebrew_curl_root_domains << domain if domain.present? homebrew_curl_root_domains << domain if domain.present?
end end
@ -707,14 +702,9 @@ resource: false)
end end
next if strategy.blank? next if strategy.blank?
homebrew_curl = case strategy_name
when "PageMatch", "HeaderMatch"
use_homebrew_curl?(resource, url)
end
puts "Homebrew curl?: Yes" if debug && homebrew_curl.present?
strategy_data = strategy.find_versions( strategy_data = strategy.find_versions(
url: url, regex: livecheck_regex, url: url, regex: livecheck_regex,
homebrew_curl: homebrew_curl, &livecheck_strategy_block homebrew_curl: false, &livecheck_strategy_block
) )
match_version_map = strategy_data[:matches] match_version_map = strategy_data[:matches]
regex = strategy_data[:regex] regex = strategy_data[:regex]
@ -791,7 +781,6 @@ resource: false)
res_livecheck[:url][:strategy] = strategy_data[:url] res_livecheck[:url][:strategy] = strategy_data[:url]
end end
res_livecheck[:url][:final] = strategy_data[:final_url] if strategy_data[:final_url] res_livecheck[:url][:final] = strategy_data[:final_url] if strategy_data[:final_url]
res_livecheck[:url][:homebrew_curl] = homebrew_curl if homebrew_curl.present?
res_livecheck[:strategy] = strategy.present? ? strategy_name : nil res_livecheck[:strategy] = strategy.present? ? strategy_name : nil
if strategies.present? if strategies.present?
res_livecheck[:strategies] = strategies.map do |s| res_livecheck[:strategies] = strategies.map do |s|

View File

@ -81,7 +81,7 @@ describe Homebrew::Livecheck do
end end
it "returns the full name of the resource" do it "returns the full name of the resource" do
expect(livecheck.resource_name(r, full_name: true)).to eq("test--foo") expect(livecheck.resource_name(r, full_name: true)).to eq("foo")
end end
end end
@ -235,21 +235,9 @@ describe Homebrew::Livecheck do
url "https://formulae.brew.sh/api/formula/ruby.json" url "https://formulae.brew.sh/api/formula/ruby.json"
regex(/"stable":"(\d+(?:\.\d+)+)"/i) regex(/"stable":"(\d+(?:\.\d+)+)"/i)
end end
resource "foo" do
url "https://brew.sh/foo-1.0.tar.gz", using: :homebrew_curl
sha256 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
livecheck do
url "https://brew.sh/test/releases"
regex(/foo[._-]v?(\d+(?:\.\d+)+)\.t/i)
end
end
end end
end end
let(:r_homebrew_curl) { f_homebrew_curl.resources.first }
let(:c_homebrew_curl) do let(:c_homebrew_curl) do
Cask::CaskLoader.load(+<<-RUBY) Cask::CaskLoader.load(+<<-RUBY)
cask "test" do cask "test" do
@ -282,13 +270,6 @@ describe Homebrew::Livecheck do
expect(livecheck.use_homebrew_curl?(c_homebrew_curl, example_url)).to be(false) expect(livecheck.use_homebrew_curl?(c_homebrew_curl, example_url)).to be(false)
end end
it "returns `false` if a `using: homebrew_curl` is present in a resource url" do
expect(livecheck.use_homebrew_curl?(r_homebrew_curl, livecheck_url)).to be(false)
expect(livecheck.use_homebrew_curl?(r_homebrew_curl, homepage_url)).to be(false)
expect(livecheck.use_homebrew_curl?(r_homebrew_curl, stable_url)).to be(false)
expect(livecheck.use_homebrew_curl?(r_homebrew_curl, example_url)).to be(false)
end
it "returns `false` if a `using: homebrew_curl` URL is not present" do it "returns `false` if a `using: homebrew_curl` URL is not present" do
expect(livecheck.use_homebrew_curl?(f, livecheck_url)).to be(false) expect(livecheck.use_homebrew_curl?(f, livecheck_url)).to be(false)
expect(livecheck.use_homebrew_curl?(f, homepage_url)).to be(false) expect(livecheck.use_homebrew_curl?(f, homepage_url)).to be(false)
@ -302,7 +283,6 @@ describe Homebrew::Livecheck do
it "returns `false` if URL string does not contain a domain" do it "returns `false` if URL string does not contain a domain" do
expect(livecheck.use_homebrew_curl?(f_homebrew_curl, "test")).to be(false) expect(livecheck.use_homebrew_curl?(f_homebrew_curl, "test")).to be(false)
expect(livecheck.use_homebrew_curl?(r_homebrew_curl, "test")).to be(false)
end end
end end