Class: Dependabot::UpdateCheckers::Base

Inherits:
Object
  • Object
show all
Extended by:
T::Helpers, T::Sig
Defined in:
lib/dependabot/update_checkers/base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dependency:, dependency_files:, credentials:, repo_contents_path: nil, ignored_versions: [], raise_on_ignored: false, security_advisories: [], requirements_update_strategy: nil, dependency_group: nil, update_cooldown: nil, options: {}) ⇒ Base

Returns a new instance of Base.



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/dependabot/update_checkers/base.rb', line 68

def initialize(
  dependency:,
  dependency_files:,
  credentials:,
  repo_contents_path: nil,
  ignored_versions: [],
  raise_on_ignored: false,
  security_advisories: [],
  requirements_update_strategy: nil,
  dependency_group: nil,
  update_cooldown: nil,
  options: {}
)
  @dependency = dependency
  @dependency_files = dependency_files
  @repo_contents_path = repo_contents_path
  @credentials = credentials
  @requirements_update_strategy = requirements_update_strategy
  @ignored_versions = ignored_versions
  @raise_on_ignored = raise_on_ignored
  @security_advisories = security_advisories
  @dependency_group = dependency_group
  @update_cooldown = update_cooldown
  @options = options
end

Instance Attribute Details

#credentialsObject (readonly)

Returns the value of attribute credentials.



29
30
31
# File 'lib/dependabot/update_checkers/base.rb', line 29

def credentials
  @credentials
end

#dependencyObject (readonly)

Returns the value of attribute dependency.



20
21
22
# File 'lib/dependabot/update_checkers/base.rb', line 20

def dependency
  @dependency
end

#dependency_filesObject (readonly)

Returns the value of attribute dependency_files.



23
24
25
# File 'lib/dependabot/update_checkers/base.rb', line 23

def dependency_files
  @dependency_files
end

#dependency_groupObject (readonly)

Returns the value of attribute dependency_group.



44
45
46
# File 'lib/dependabot/update_checkers/base.rb', line 44

def dependency_group
  @dependency_group
end

#ignored_versionsObject (readonly)

Returns the value of attribute ignored_versions.



32
33
34
# File 'lib/dependabot/update_checkers/base.rb', line 32

def ignored_versions
  @ignored_versions
end

#optionsObject (readonly)

Returns the value of attribute options.



50
51
52
# File 'lib/dependabot/update_checkers/base.rb', line 50

def options
  @options
end

#raise_on_ignoredObject (readonly)

Returns the value of attribute raise_on_ignored.



35
36
37
# File 'lib/dependabot/update_checkers/base.rb', line 35

def raise_on_ignored
  @raise_on_ignored
end

#repo_contents_pathObject (readonly)

Returns the value of attribute repo_contents_path.



26
27
28
# File 'lib/dependabot/update_checkers/base.rb', line 26

def repo_contents_path
  @repo_contents_path
end

#requirements_update_strategyObject (readonly)

Returns the value of attribute requirements_update_strategy.



41
42
43
# File 'lib/dependabot/update_checkers/base.rb', line 41

def requirements_update_strategy
  @requirements_update_strategy
end

#security_advisoriesObject (readonly)

Returns the value of attribute security_advisories.



38
39
40
# File 'lib/dependabot/update_checkers/base.rb', line 38

def security_advisories
  @security_advisories
end

#update_cooldownObject (readonly)

Returns the value of attribute update_cooldown.



47
48
49
# File 'lib/dependabot/update_checkers/base.rb', line 47

def update_cooldown
  @update_cooldown
end

Instance Method Details

#can_update?(requirements_to_unlock:) ⇒ Boolean

Returns:

  • (Boolean)


104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/dependabot/update_checkers/base.rb', line 104

def can_update?(requirements_to_unlock:)
  # Can't update if all versions are being ignored
  return false if ignore_requirements.include?(requirement_class.new(">= 0"))

  if dependency.version
    version_can_update?(requirements_to_unlock: requirements_to_unlock)
  else
    # TODO: Handle full unlock updates for dependencies without a lockfile
    return false if requirements_to_unlock == :none

    requirements_can_update?
  end
end

#conflicting_dependenciesObject



176
177
178
# File 'lib/dependabot/update_checkers/base.rb', line 176

def conflicting_dependencies
  [] # return an empty array for ecosystems that don't support this yet
end

#ignore_requirementsObject



223
224
225
# File 'lib/dependabot/update_checkers/base.rb', line 223

def ignore_requirements
  ignored_versions.flat_map { |req| requirement_class.requirements_array(req) }
end

#latest_resolvable_previous_version(_updated_version) ⇒ Object



181
182
183
# File 'lib/dependabot/update_checkers/base.rb', line 181

def latest_resolvable_previous_version(_updated_version)
  dependency.version
end

#latest_resolvable_versionObject

Raises:

  • (NotImplementedError)


148
149
150
# File 'lib/dependabot/update_checkers/base.rb', line 148

def latest_resolvable_version
  raise NotImplementedError, "#{self.class} must implement #latest_resolvable_version"
end

#latest_resolvable_version_with_no_unlockObject

Raises:

  • (NotImplementedError)


165
166
167
# File 'lib/dependabot/update_checkers/base.rb', line 165

def latest_resolvable_version_with_no_unlock
  raise NotImplementedError, "#{self.class} must implement #latest_resolvable_version_with_no_unlock"
end

#latest_versionObject

Raises:

  • (NotImplementedError)


131
132
133
# File 'lib/dependabot/update_checkers/base.rb', line 131

def latest_version
  raise NotImplementedError, "#{self.class} must implement #latest_version"
end

#lowest_resolvable_security_fix_versionObject

Raises:

  • (NotImplementedError)


160
161
162
# File 'lib/dependabot/update_checkers/base.rb', line 160

def lowest_resolvable_security_fix_version
  raise NotImplementedError, "#{self.class} must implement #lowest_resolvable_security_fix_version"
end

#lowest_security_fix_versionObject

Raises:

  • (NotImplementedError)


155
156
157
# File 'lib/dependabot/update_checkers/base.rb', line 155

def lowest_security_fix_version
  raise NotImplementedError, "#{self.class} must implement #lowest_security_fix_version"
end

#preferred_resolvable_versionObject



136
137
138
139
140
141
142
143
144
145
# File 'lib/dependabot/update_checkers/base.rb', line 136

def preferred_resolvable_version
  # If this dependency is vulnerable, prefer trying to update to the
  # lowest_resolvable_security_fix_version. Otherwise update all the way
  # to the latest_resolvable_version.
  return lowest_resolvable_security_fix_version if vulnerable?

  latest_resolvable_version
rescue NotImplementedError
  latest_resolvable_version
end

#requirement_classObject



196
197
198
# File 'lib/dependabot/update_checkers/base.rb', line 196

def requirement_class
  dependency.requirement_class
end

#requirements_unlocked_or_can_be?Boolean

Returns:

  • (Boolean)


204
205
206
# File 'lib/dependabot/update_checkers/base.rb', line 204

def requirements_unlocked_or_can_be?
  true
end

#up_to_date?Boolean

Returns:

  • (Boolean)


95
96
97
98
99
100
101
# File 'lib/dependabot/update_checkers/base.rb', line 95

def up_to_date?
  if dependency.version
    version_up_to_date?
  else
    requirements_up_to_date?
  end
end

#updated_dependencies(requirements_to_unlock:) ⇒ Object



119
120
121
122
123
124
125
126
127
128
# File 'lib/dependabot/update_checkers/base.rb', line 119

def updated_dependencies(requirements_to_unlock:)
  return [] unless can_update?(requirements_to_unlock: requirements_to_unlock)

  case requirements_to_unlock&.to_sym
  when :none then [updated_dependency_without_unlock]
  when :own then [updated_dependency_with_own_req_unlock]
  when :all then updated_dependencies_after_full_unlock
  else raise "Unknown unlock level '#{requirements_to_unlock}'"
  end
end

#updated_requirementsObject

Raises:

  • (NotImplementedError)


186
187
188
# File 'lib/dependabot/update_checkers/base.rb', line 186

def updated_requirements
  raise NotImplementedError
end

#version_classObject



191
192
193
# File 'lib/dependabot/update_checkers/base.rb', line 191

def version_class
  dependency.version_class
end

#vulnerable?Boolean

Returns:

  • (Boolean)


209
210
211
212
213
214
215
216
217
218
219
220
# File 'lib/dependabot/update_checkers/base.rb', line 209

def vulnerable?
  return false if security_advisories.none?

  # Can't (currently) detect whether dependencies without a version
  # (i.e., for repos without a lockfile) are vulnerable
  return false unless dependency.version

  # Can't (currently) detect whether git dependencies are vulnerable
  return false if existing_version_is_sha?

  active_advisories.any?
end