Module: Dependabot::UpdateCheckers::CooldownCalculation

Extended by:
T::Sig
Defined in:
lib/dependabot/update_checkers/cooldown_calculation.rb

Overview

Shared utility module for cooldown period calculations.

Provides stateless module methods used by ecosystem update checkers to determine whether a release is within its cooldown window and how many cooldown days apply for a given version bump.

Constant Summary collapse

DAY_IN_SECONDS =
T.let(24 * 60 * 60, Integer)
DATE_UNAVAILABLE_METADATA_KEY =
:cooldown_date_unavailable
DATE_UNAVAILABLE_NOTICE_TYPE =

Shared by the pull request notice and the job-level warning so both channels report the same diagnostic, whether or not the update produced a pull request.

"cooldown_date_unavailable"
DATE_UNAVAILABLE_TITLE =
"Cooldown was not applied"
DATE_UNAVAILABLE_DESCRIPTION =
"Cooldown could not be applied because no publication date was available from the registry."

Class Method Summary collapse

Class Method Details

.cooldown_date_unavailable?(dependency) ⇒ Boolean

Returns:

  • (Boolean)


71
72
73
# File 'lib/dependabot/update_checkers/cooldown_calculation.rb', line 71

def self.cooldown_date_unavailable?(dependency)
  dependency.[] == true
end

.cooldown_days_for(cooldown, current_version, new_version) ⇒ Object



43
44
45
46
47
48
49
50
# File 'lib/dependabot/update_checkers/cooldown_calculation.rb', line 43

def self.cooldown_days_for(cooldown, current_version, new_version)
  return cooldown.default_days unless current_version

  cooldown.cooldown_days_for(
    current_version.semver_parts,
    new_version.semver_parts
  )
end

.mark_cooldown_date_unavailable(dependency, cooldown_days:) ⇒ Object



64
65
66
67
68
# File 'lib/dependabot/update_checkers/cooldown_calculation.rb', line 64

def self.mark_cooldown_date_unavailable(dependency, cooldown_days:)
  return unless cooldown_days.positive?

  dependency.[] = true
end

.skip_cooldown?(cooldown, dependency_name, cooldown_enabled: true) ⇒ Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/dependabot/update_checkers/cooldown_calculation.rb', line 59

def self.skip_cooldown?(cooldown, dependency_name, cooldown_enabled: true)
  cooldown.nil? || !cooldown_enabled || !cooldown.included?(dependency_name)
end

.within_cooldown_window?(release_date, cooldown_days) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
33
34
# File 'lib/dependabot/update_checkers/cooldown_calculation.rb', line 30

def self.within_cooldown_window?(release_date, cooldown_days)
  return false if cooldown_days <= 0

  (Time.now.to_i - release_date.to_i) < (cooldown_days * DAY_IN_SECONDS)
end