Class: Dependabot::Nuget::UpdateChecker::PropertyUpdater

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/dependabot/nuget/update_checker/property_updater.rb

Instance Method Summary collapse

Constructor Details

#initialize(dependency:, dependency_files:, credentials:, target_version_details:, ignored_versions:, repo_contents_path:, raise_on_ignored: false) ⇒ PropertyUpdater

Returns a new instance of PropertyUpdater.



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/dependabot/nuget/update_checker/property_updater.rb', line 30

def initialize(dependency:, dependency_files:, credentials:,
               target_version_details:, ignored_versions:,
               repo_contents_path:, raise_on_ignored: false)
  @dependency       = dependency
  @dependency_files = dependency_files
  @credentials      = credentials
  @ignored_versions = ignored_versions
  @raise_on_ignored = raise_on_ignored
  @target_version   = T.let(
    target_version_details&.fetch(:version),
    T.nilable(T.any(String, Dependabot::Nuget::Version))
  )
  @source_details = T.let(
    target_version_details&.slice(:nuspec_url, :repo_url, :source_url),
    T.nilable(T::Hash[Symbol, String])
  )
  @repo_contents_path = repo_contents_path
end

Instance Method Details

#update_possible?Boolean

Returns:

  • (Boolean)


50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/dependabot/nuget/update_checker/property_updater.rb', line 50

def update_possible?
  return false unless target_version

  @update_possible ||= T.let(
    dependencies_using_property.all? do |dep|
      versions = VersionFinder.new(
        dependency: dep,
        dependency_files: dependency_files,
        credentials: credentials,
        ignored_versions: ignored_versions,
        raise_on_ignored: @raise_on_ignored,
        security_advisories: [],
        repo_contents_path: repo_contents_path
      ).versions.map { |v| v.fetch(:version) }

      versions.include?(target_version) || versions.none?
    end,
    T.nilable(T::Boolean)
  )
end

#updated_dependenciesObject



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/dependabot/nuget/update_checker/property_updater.rb', line 72

def updated_dependencies
  raise "Update not possible!" unless update_possible?

  @updated_dependencies ||= T.let(
    begin
      dependencies = T.let({}, T::Hash[String, Dependabot::Dependency])

      dependencies_using_property.each do |dep|
        # Only keep one copy of each dependency, the one with the highest target version.
        visited_dependency = dependencies[dep.name.downcase]
        next unless visited_dependency.nil? || T.must(visited_dependency.numeric_version) < target_version

        updated_dependency = Dependency.new(
          name: dep.name,
          version: target_version.to_s,
          requirements: updated_requirements(dep),
          previous_version: dep.version,
          previous_requirements: dep.requirements,
          package_manager: dep.package_manager
        )
        dependencies[updated_dependency.name.downcase] = updated_dependency
        # Add peer dependencies to the list of updated dependencies.
        process_updated_peer_dependencies(updated_dependency, dependencies)
      end

      dependencies.map { |_, dependency| dependency }
    end,
    T.nilable(T::Array[Dependabot::Dependency])
  )
end