Skip to content

Commit

Permalink
livecheck: Add throttle info to debug, JSON output
Browse files Browse the repository at this point in the history
  • Loading branch information
samford committed Mar 21, 2024
1 parent 7ff01d8 commit d28d2df
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions Library/Homebrew/livecheck/livecheck.rb
Expand Up @@ -356,9 +356,10 @@ def run_checks(
info[:version] = {
current: current_str,
latest: latest_str,
latest_throttled: version_info&.dig(:latest_throttled),
outdated: is_outdated,
newer_than_upstream: is_newer_than_upstream,
}
}.compact
info[:meta] = {
livecheckable: formula_or_cask.livecheckable?,
}
Expand Down Expand Up @@ -662,6 +663,7 @@ def latest_version(
livecheck_regex = livecheck.regex || referenced_livecheck&.regex
livecheck_strategy = livecheck.strategy || referenced_livecheck&.strategy
livecheck_strategy_block = livecheck.strategy_block || referenced_livecheck&.strategy_block
livecheck_throttle = livecheck.throttle || referenced_livecheck&.throttle

livecheck_url_string = livecheck_url_to_string(
livecheck_url,
Expand All @@ -679,6 +681,7 @@ def latest_version(
puts "Cask: #{cask_name(formula_or_cask, full_name:)}"
end
puts "Livecheckable?: #{has_livecheckable ? "Yes" : "No"}"
puts "Throttle: #{livecheck_throttle}" if livecheck_throttle

livecheck_references.each do |ref_formula_or_cask|
case ref_formula_or_cask
Expand Down Expand Up @@ -810,8 +813,8 @@ def latest_version(
latest: Version.new(match_version_map.values.max_by { |v| LivecheckVersion.create(formula_or_cask, v) }),
}

if (throttle = livecheck.throttle || referenced_livecheck&.throttle)
match_version_map.keep_if { |_match, version| version.patch.to_i.modulo(throttle).zero? }
if livecheck_throttle
match_version_map.keep_if { |_match, version| version.patch.to_i.modulo(livecheck_throttle).zero? }
version_info[:latest_throttled] = if match_version_map.blank?
nil
else
Expand Down Expand Up @@ -860,6 +863,7 @@ def latest_version(
version_info[:meta][:strategies] = strategies.map { |s| livecheck_strategy_names[s] } if strategies.present?
version_info[:meta][:regex] = regex.inspect if regex.present?
version_info[:meta][:cached] = true if strategy_data[:cached] == true
version_info[:meta][:throttle] = livecheck_throttle if livecheck_throttle
end

return version_info
Expand Down

0 comments on commit d28d2df

Please sign in to comment.