Class: Dependabot::Nuget::UpdateChecker::DependencyFinder
- Inherits:
-
Object
- Object
- Dependabot::Nuget::UpdateChecker::DependencyFinder
- Extended by:
- T::Sig
- Defined in:
- lib/dependabot/nuget/update_checker/dependency_finder.rb
Class Method Summary collapse
- .fetch_dependencies_cache ⇒ Object
- .transitive_dependencies_cache ⇒ Object
- .updated_peer_dependencies_cache ⇒ Object
Instance Method Summary collapse
-
#initialize(dependency:, dependency_files:, ignored_versions:, credentials:, repo_contents_path:) ⇒ DependencyFinder
constructor
A new instance of DependencyFinder.
- #transitive_dependencies ⇒ Object
- #updated_peer_dependencies ⇒ Object
Constructor Details
#initialize(dependency:, dependency_files:, ignored_versions:, credentials:, repo_contents_path:) ⇒ DependencyFinder
Returns a new instance of DependencyFinder.
45 46 47 48 49 50 51 |
# File 'lib/dependabot/nuget/update_checker/dependency_finder.rb', line 45 def initialize(dependency:, dependency_files:, ignored_versions:, credentials:, repo_contents_path:) @dependency = dependency @dependency_files = dependency_files @ignored_versions = ignored_versions @credentials = credentials @repo_contents_path = repo_contents_path end |
Class Method Details
.fetch_dependencies_cache ⇒ Object
32 33 34 |
# File 'lib/dependabot/nuget/update_checker/dependency_finder.rb', line 32 def self.fetch_dependencies_cache CacheManager.cache("dependency_finder_fetch_dependencies") end |
.transitive_dependencies_cache ⇒ Object
22 23 24 |
# File 'lib/dependabot/nuget/update_checker/dependency_finder.rb', line 22 def self.transitive_dependencies_cache CacheManager.cache("dependency_finder_transitive_dependencies") end |
.updated_peer_dependencies_cache ⇒ Object
27 28 29 |
# File 'lib/dependabot/nuget/update_checker/dependency_finder.rb', line 27 def self.updated_peer_dependencies_cache CacheManager.cache("dependency_finder_updated_peer_dependencies") end |
Instance Method Details
#transitive_dependencies ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/dependabot/nuget/update_checker/dependency_finder.rb', line 54 def transitive_dependencies key = "#{dependency.name.downcase}::#{dependency.version}" cache = DependencyFinder.transitive_dependencies_cache unless cache[key] begin # first do a quick sanity check on the version string; if it can't be parsed, an exception will be raised _ = Version.new(dependency.version) cache[key] = fetch_transitive_dependencies( @dependency.name, T.must(@dependency.version) ).map do |dependency_info| package_name = dependency_info["packageName"] target_version = dependency_info["version"] Dependency.new( name: package_name, version: target_version.to_s, requirements: [], # Empty requirements for transitive dependencies package_manager: @dependency.package_manager ) end rescue StandardError # if anything happened above, there are no meaningful dependencies that can be derived cache[key] = [] end end cache[key] end |
#updated_peer_dependencies ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/dependabot/nuget/update_checker/dependency_finder.rb', line 87 def updated_peer_dependencies key = "#{dependency.name.downcase}::#{dependency.version}" cache = DependencyFinder.updated_peer_dependencies_cache cache[key] ||= fetch_transitive_dependencies( @dependency.name, T.must(@dependency.version) ).filter_map do |dependency_info| package_name = dependency_info["packageName"] target_version = dependency_info["version"] # Find the Dependency object for the peer dependency. We will not return # dependencies that are not referenced from dependency files. peer_dependency = top_level_dependencies.find { |d| d.name == package_name } next unless peer_dependency next unless target_version > peer_dependency.numeric_version # Use version finder to determine the source details for the peer dependency. target_version_details = version_finder(peer_dependency).versions.find do |v| v.fetch(:version) == target_version end next unless target_version_details Dependency.new( name: peer_dependency.name, version: target_version_details.fetch(:version).to_s, requirements: updated_requirements(peer_dependency, target_version_details), previous_version: peer_dependency.version, previous_requirements: peer_dependency.requirements, package_manager: peer_dependency.package_manager, metadata: { information_only: true } # Instruct updater to not directly update this dependency ) end cache[key] end |