Class: Dependabot::GitSubmodules::UpdateChecker::LatestVersionFinder

Inherits:
Package::PackageLatestVersionFinder
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/dependabot/git_submodules/update_checker/latest_version_finder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dependency:, credentials:, cooldown_options:) ⇒ LatestVersionFinder

Returns a new instance of LatestVersionFinder.



28
29
30
31
32
# File 'lib/dependabot/git_submodules/update_checker/latest_version_finder.rb', line 28

def initialize(dependency:, credentials:, cooldown_options:)
  @dependency = dependency
  @credentials = credentials
  @cooldown_options = cooldown_options
end

Instance Attribute Details

#cooldown_optionsObject (readonly)

Returns the value of attribute cooldown_options.



126
127
128
# File 'lib/dependabot/git_submodules/update_checker/latest_version_finder.rb', line 126

def cooldown_options
  @cooldown_options
end

#credentialsObject (readonly)

Returns the value of attribute credentials.



123
124
125
# File 'lib/dependabot/git_submodules/update_checker/latest_version_finder.rb', line 123

def credentials
  @credentials
end

#dependencyObject (readonly)

Returns the value of attribute dependency.



120
121
122
# File 'lib/dependabot/git_submodules/update_checker/latest_version_finder.rb', line 120

def dependency
  @dependency
end

Instance Method Details

#apply_post_fetch_latest_versions_filter(releases) ⇒ Object



105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/dependabot/git_submodules/update_checker/latest_version_finder.rb', line 105

def apply_post_fetch_latest_versions_filter(releases)
  if releases.empty?
    Dependabot.logger.info("No releases found for #{dependency.name} after applying filters.")
    return releases
  end

  releases << Dependabot::Package::PackageRelease.new(
    version: GitSubmodules::Version.new("1.0.0"),
    tag: dependency.version
  )

  releases
end

#cooldown_daysObject



82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/dependabot/git_submodules/update_checker/latest_version_finder.rb', line 82

def cooldown_days
  cooldown = @cooldown_options
  return 0 if cooldown.nil?
  return 0 unless cooldown_enabled?
  return 0 unless cooldown.included?(dependency.name)

  return cooldown.default_days if cooldown.default_days.positive?
  return cooldown.semver_major_days if cooldown.semver_major_days.positive?
  return cooldown.semver_minor_days if cooldown.semver_minor_days.positive?
  return cooldown.semver_patch_days if cooldown.semver_patch_days.positive?

  cooldown.default_days
end

#cooldown_enabled?Boolean

Returns:

  • (Boolean)


97
98
99
# File 'lib/dependabot/git_submodules/update_checker/latest_version_finder.rb', line 97

def cooldown_enabled?
  true
end

#in_cooldown_period?(release) ⇒ Boolean

Returns:

  • (Boolean)


58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/dependabot/git_submodules/update_checker/latest_version_finder.rb', line 58

def in_cooldown_period?(release)
  unless release.released_at
    Dependabot.logger.info("Release date not available for ref tag #{release.tag}")
    return false
  end

  days = cooldown_days
  passed_seconds = Time.now.to_i - release.released_at.to_i
  passed_days = passed_seconds / DAY_IN_SECONDS

  if passed_days < days
    Dependabot.logger.info(
      "Filtered #{release.tag}, Released on: " \
      "#{T.must(release.released_at).strftime('%Y-%m-%d')} " \
      "(#{passed_days}/#{days} cooldown days)"
    )
  end

  passed_seconds < days * DAY_IN_SECONDS
end

#latest_tagObject



35
36
37
38
39
40
41
42
43
# File 'lib/dependabot/git_submodules/update_checker/latest_version_finder.rb', line 35

def latest_tag
  releases = version_list

  releases = filter_by_cooldown(T.must(releases))

  # if there are no releases after applying filters, we fallback to the current tag to avoid empty results
  releases = apply_post_fetch_latest_versions_filter(releases)
  releases.first&.tag
end

#package_detailsObject



129
# File 'lib/dependabot/git_submodules/update_checker/latest_version_finder.rb', line 129

def package_details; end

#version_listObject



46
47
48
49
50
51
52
53
54
55
# File 'lib/dependabot/git_submodules/update_checker/latest_version_finder.rb', line 46

def version_list
  @version_list ||=
    T.let(
      Package::PackageDetailsFetcher.new(
        dependency: dependency,
        credentials: credentials
      ).available_versions,
      T.nilable(T::Array[Dependabot::Package::PackageRelease])
    )
end