/
file_parser.rb
86 lines (69 loc) 路 2.7 KB
/
file_parser.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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
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
85
86
# typed: strong
# frozen_string_literal: true
require "dependabot/dependency"
require "dependabot/file_parsers"
require "dependabot/file_parsers/base"
require "dependabot/nuget/discovery/discovery_json_reader"
require "dependabot/nuget/native_helpers"
require "sorbet-runtime"
# For details on how dotnet handles version constraints, see:
# https://docs.microsoft.com/en-us/nuget/reference/package-versioning
module Dependabot
module Nuget
class FileParser < Dependabot::FileParsers::Base
extend T::Sig
require "dependabot/file_parsers/base/dependency_set"
sig { override.returns(T::Array[Dependabot::Dependency]) }
def parse
workspace_path = project_files.first&.directory
return [] unless workspace_path
return [] unless repo_contents_path
# `workspace_path` is the only unique value here so we use it as the cache key
cache = T.let(CacheManager.cache("file_parser.parse"), T::Hash[String, T::Array[Dependabot::Dependency]])
key = workspace_path
cache[key] ||= begin
# run discovery for the repo
NativeHelpers.run_nuget_discover_tool(repo_root: T.must(repo_contents_path),
workspace_path: workspace_path,
output_path: DiscoveryJsonReader.discovery_file_path,
credentials: credentials)
discovered_dependencies.dependencies
end
T.must(cache[key])
end
private
sig { returns(Dependabot::FileParsers::Base::DependencySet) }
def discovered_dependencies
discovery_json = DiscoveryJsonReader.discovery_json
return DependencySet.new unless discovery_json
Dependabot.logger.info("Discovery JSON content: #{discovery_json.content}")
DiscoveryJsonReader.new(
discovery_json: discovery_json
).dependency_set
end
sig { returns(T::Array[Dependabot::DependencyFile]) }
def proj_files
projfile = /\.proj$/
dependency_files.select do |df|
df.name.match?(projfile)
end
end
sig { returns(T::Array[Dependabot::DependencyFile]) }
def project_files
projectfile = /\.(cs|vb|fs)proj$/
dependency_files.select do |df|
df.name.match?(projectfile)
end
end
sig { override.void }
def check_required_files
return if project_files.any? || proj_files.any?
raise Dependabot::DependencyFileNotFound.new(
"*.(cs|vb|fs)proj, *.proj",
"No project file or *.proj!"
)
end
end
end
end
Dependabot::FileParsers.register("nuget", Dependabot::Nuget::FileParser)