Class: Dependabot::Nuget::FileParser

Inherits:
FileParsers::Base
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/dependabot/nuget/file_parser.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.file_dependency_cacheObject



22
23
24
# File 'lib/dependabot/nuget/file_parser.rb', line 22

def self.file_dependency_cache
  T.let(CacheManager.cache("file_parser.parse"), T::Hash[String, T::Array[Dependabot::Dependency]])
end

Instance Method Details

#parseObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/dependabot/nuget/file_parser.rb', line 27

def parse
  return [] unless repo_contents_path

  key = NativeDiscoveryJsonReader.create_cache_key(dependency_files)
  workspace_path = source&.directory || "/"
  self.class.file_dependency_cache[key] ||= begin
    # run discovery for the repo
    discovery_json_path = NativeDiscoveryJsonReader.create_discovery_file_path_from_dependency_files(
      dependency_files
    )
    NativeHelpers.run_nuget_discover_tool(repo_root: T.must(repo_contents_path),
                                          workspace_path: workspace_path,
                                          output_path: discovery_json_path,
                                          credentials: credentials)

    discovery_json = NativeDiscoveryJsonReader.discovery_json_from_path(discovery_json_path)
    return [] unless discovery_json

    Dependabot.logger.info("Discovery JSON content: #{discovery_json.content}")
    discovery_json_reader = NativeDiscoveryJsonReader.new(
      discovery_json: discovery_json
    )

    # cache discovery results
    NativeDiscoveryJsonReader.set_discovery_from_dependency_files(dependency_files: dependency_files,
                                                                  discovery: discovery_json_reader)
    discovery_json_reader.dependency_set.dependencies
  end

  T.must(self.class.file_dependency_cache[key])
end