Use Sparkle sorting/filtering in #livecheck_min_os

The `#livecheck_min_os` cask audit method manually replicates some of
the `Sparkle` strategy's behavior but in an incomplete way that has
lead to inappropriate audit failures at times. This reimplements it
to use `Livecheck` methods, so it will align with the `Sparkle`
strategy's behavior.
This commit is contained in:
Sam Ford 2023-11-08 09:29:10 -05:00
parent d376b46a7d
commit 28451bd2bc
No known key found for this signature in database
GPG Key ID: 7AF5CBEE1DD6F76D

View File

@ -603,31 +603,25 @@ module Cask
return if cask.livecheck.strategy_block.present? &&
cask.livecheck.strategy_block.parameters[0] == [:opt, :items]
out, _, status = curl_output("--fail", "--silent", "--location", cask.livecheck.url)
return unless status.success?
require "rexml/document"
xml = begin
REXML::Document.new(out)
rescue REXML::ParseException
nil
end
return if xml.blank?
item = xml.elements["//rss//channel//item"]
return if item.blank?
min_os = item.elements["sparkle:minimumSystemVersion"]&.text
min_os = "11" if min_os == "10.16"
return if min_os.blank?
content = Homebrew::Livecheck::Strategy.page_content(cask.livecheck.url)[:content]
return if content.blank?
begin
MacOSVersion.new(min_os).strip_patch
rescue MacOSVersion::Error
nil
items = Homebrew::Livecheck::Strategy::Sparkle.sort_items(
Homebrew::Livecheck::Strategy::Sparkle.filter_items(
Homebrew::Livecheck::Strategy::Sparkle.items_from_content(content),
),
)
rescue
return
end
return if items.blank?
min_os = items[0]&.minimum_system_version&.strip_patch
# Big Sur is sometimes identified as 10.16, so we override it to the
# expected macOS version (11).
min_os = MacOSVersion.new("11") if min_os == "10.16"
min_os
end
sig { returns(T.nilable(MacOSVersion)) }