From a28e1aa422c02c6afd674545dbbbd5efcbb02a3b Mon Sep 17 00:00:00 2001 From: Sam Ford <1584702+samford@users.noreply.github.com> Date: Fri, 28 Apr 2023 17:23:30 -0400 Subject: [PATCH] livecheck: Selectively pass args to #find_versions The existing way of passing values to `#find_versions` methods in strategies leads to type issues when the Sorbet runtime is enabled. We've also recently talked about moving away from nilable args when we can specify a default value but this doesn't work if we pass in a `nil` value (like we're currently doing). This commit aims to address both of those areas by better controlling which arguments we're passing to `#find_versions`. This approach naively handles `cask`/`url` arguments by special-casing `ExtractPlist`. However, we should be checking the strategy's `#find_versions` method for a `cask` or `url` keyword parameter. The issue is that `strategy.method(:find_versions).parameters` is returning `[[:rest, :args], [:block, :blk]]` instead of the actual parameters like `[[:keyreq, :url], [:key, :regex], [:keyrest, :unused], [:block, :block]]`. --- Library/Homebrew/livecheck/livecheck.rb | 26 +++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/Library/Homebrew/livecheck/livecheck.rb b/Library/Homebrew/livecheck/livecheck.rb index e41891e39f..06eaf7bf71 100644 --- a/Library/Homebrew/livecheck/livecheck.rb +++ b/Library/Homebrew/livecheck/livecheck.rb @@ -733,13 +733,22 @@ module Homebrew end puts "Homebrew curl?: Yes" if debug && homebrew_curl.present? - strategy_data = strategy.find_versions( - url: url, + strategy_args = { regex: livecheck_regex, homebrew_curl: homebrew_curl, - cask: cask, - &livecheck_strategy_block - ) + } + # TODO: Set `cask`/`url` args based on the presence of the keyword arg + # in the strategy's `#find_versions` method once we figure out why + # `strategy.method(:find_versions).parameters` isn't working as + # expected. + if strategy_name == "ExtractPlist" + strategy_args[:cask] = cask if cask.present? + else + strategy_args[:url] = url + end + strategy_args.compact! + + strategy_data = strategy.find_versions(**strategy_args, &livecheck_strategy_block) match_version_map = strategy_data[:matches] regex = strategy_data[:regex] messages = strategy_data[:messages] @@ -912,12 +921,13 @@ module Homebrew puts if debug && strategy.blank? next if strategy.blank? - strategy_data = strategy.find_versions( + strategy_args = { url: url, regex: livecheck_regex, homebrew_curl: false, - &livecheck_strategy_block - ) + }.compact + + strategy_data = strategy.find_versions(**strategy_args, &livecheck_strategy_block) match_version_map = strategy_data[:matches] regex = strategy_data[:regex] messages = strategy_data[:messages]