Module: Homebrew::Livecheck::Throttle Private

Extended by:
T::Helpers
Included in:
Homebrew::Livecheck
Defined in:
livecheck/throttle.rb

Overview

This module is part of a private API. This module may only be used in the Homebrew/brew repository. Third parties should avoid using this module if possible, as it may be removed or changed without warning.

Release selection and version-update history for throttling.

Instance Method Summary collapse

Instance Method Details

#formula_or_cask_last_updated_timestamp(formula_or_cask) ⇒ Integer?

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Parameters:

Returns:



66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'livecheck/throttle.rb', line 66

def formula_or_cask_last_updated_timestamp(formula_or_cask)
  tap = formula_or_cask.tap
  return if tap.nil?
  return unless tap.git?
  return unless Utils::Git.available?

  if formula_or_cask.is_a?(Formula)
    timestamp = formula_last_version_update_timestamp(formula_or_cask, tap:)
    return timestamp if timestamp.present?
  end

  formula_or_cask_last_commit_timestamp(formula_or_cask, tap)
end

#throttle_allows_bump?(formula_or_cask, version, throttle_rate: nil, throttle_days: nil) ⇒ Boolean

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Parameters:

Returns:

  • (Boolean)


54
55
56
57
58
59
60
61
62
63
# File 'livecheck/throttle.rb', line 54

def throttle_allows_bump?(formula_or_cask, version, throttle_rate: nil, throttle_days: nil)
  return true if throttle_rate.nil? && throttle_days.nil?

  unless throttle_rate.nil?
    version = Version.new(version) unless version.is_a?(Version)
    return true if version.patch.to_i.modulo(throttle_rate).zero?
  end

  !throttle_days.nil? && throttle_interval_elapsed?(formula_or_cask, throttle_days)
end

#throttle_interval_elapsed?(formula_or_cask, days) ⇒ Boolean

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Parameters:

Returns:

  • (Boolean)


81
82
83
84
85
86
87
88
89
# File 'livecheck/throttle.rb', line 81

def throttle_interval_elapsed?(formula_or_cask, days)
  return false if days <= 0

  last_updated_timestamp = formula_or_cask_last_updated_timestamp(formula_or_cask)
  return false if last_updated_timestamp.nil?

  elapsed_seconds = Time.now.to_i - last_updated_timestamp
  elapsed_seconds >= (days * 24 * 60 * 60)
end

#throttled_version(formula_or_cask, match_version_map, latest, throttle_rate: nil, throttle_days: nil, debug: false, verbose: false) ⇒ Version?

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Parameters:

Returns:



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'livecheck/throttle.rb', line 17

def throttled_version(formula_or_cask, match_version_map, latest, throttle_rate: nil, throttle_days: nil,
                      debug: false, verbose: false)
  throttled_match_version_map = if throttle_rate
    match_version_map.select do |_match, version|
      throttle_allows_bump?(formula_or_cask, version, throttle_rate:)
    end
  else
    {}
  end

  latest_throttled = if throttle_days &&
                        throttle_allows_bump?(formula_or_cask, latest, throttle_days:)
    latest
  elsif (version = throttled_match_version_map.values.max_by do |v|
    LivecheckVersion.create(formula_or_cask, v)
  end)
    Version.new(version)
  end

  if debug
    print_matches(throttled_match_version_map, heading: "Matched Throttled Versions", verbose:)

    if latest_throttled == latest && throttled_match_version_map.blank?
      puts Tty.strip_ansi("#{latest_throttled} (throttle interval elapsed)")
    end
  end
  latest_throttled
end