From 1a7b3708ebcfc947577eec4191bb087cc3d435d3 Mon Sep 17 00:00:00 2001 From: Sam Ford <1584702+samford@users.noreply.github.com> Date: Fri, 29 Sep 2023 23:57:46 -0400 Subject: [PATCH] s/switchhosts: update livecheck --- Casks/s/switchhosts.rb | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/Casks/s/switchhosts.rb b/Casks/s/switchhosts.rb index 5da1e36c9c..a7c61e1b45 100644 --- a/Casks/s/switchhosts.rb +++ b/Casks/s/switchhosts.rb @@ -12,20 +12,15 @@ cask "switchhosts" do homepage "https://oldj.github.io/SwitchHosts/" livecheck do - url "https://github.com/oldj/SwitchHosts/releases/latest" - regex(%r{/SwitchHosts_mac_#{arch}[._-]v?(\d+(?:\.\d+)+)\.dmg}i) - strategy :header_match do |headers, regex| - next if headers["location"].blank? + url :url + regex(/^SwitchHosts_mac_#{arch}[._-]v?(\d+(?:\.\d+)+)\.dmg$/i) + strategy :github_latest do |json, regex| + json["assets"]&.map do |asset| + match = asset["name"]&.match(regex) + next if match.blank? - # Identify the latest tag from the response's `location` header - latest_tag = File.basename(headers["location"]) - next if latest_tag.blank? - - # Fetch the assets list HTML for the latest tag and match within it - assets_page = Homebrew::Livecheck::Strategy.page_content( - @url.sub(%r{/releases/?.+}, "/releases/expanded_assets/#{latest_tag}"), - ) - assets_page[:content]&.scan(regex)&.map { |match| match[0] } + match[1] + end end end