dependabot-nuget 0.289.0 → 0.291.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (97) hide show
  1. checksums.yaml +4 -4
  2. data/helpers/lib/NuGetUpdater/Directory.Packages.props +1 -1
  3. data/helpers/lib/NuGetUpdater/NuGetUpdater.Cli/Commands/AnalyzeCommand.cs +7 -3
  4. data/helpers/lib/NuGetUpdater/NuGetUpdater.Cli/Commands/RunCommand.cs +1 -1
  5. data/helpers/lib/NuGetUpdater/NuGetUpdater.Cli.Test/EntryPointTests.Analyze.cs +26 -1
  6. data/helpers/lib/NuGetUpdater/NuGetUpdater.Cli.Test/EntryPointTests.Discover.cs +2 -1
  7. data/helpers/lib/NuGetUpdater/NuGetUpdater.Cli.Test/EntryPointTests.Run.cs +0 -6
  8. data/helpers/lib/NuGetUpdater/NuGetUpdater.Cli.Test/EntryPointTests.Update.cs +1 -1
  9. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Analyze/AnalyzeWorker.cs +6 -1
  10. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Analyze/CompatabilityChecker.cs +24 -9
  11. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Analyze/DependencyFinder.cs +2 -0
  12. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Analyze/NuGetContext.cs +0 -13
  13. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Analyze/RequirementConverter.cs +17 -0
  14. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Discover/DiscoveryWorker.cs +44 -5
  15. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Discover/PackagesConfigDiscovery.cs +2 -2
  16. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Discover/ProjectDiscoveryResult.cs +2 -0
  17. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Discover/SdkProjectDiscovery.cs +19 -11
  18. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/ErrorType.cs +1 -0
  19. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/ExperimentsManager.cs +3 -0
  20. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/ApiModel/Advisory.cs +13 -0
  21. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/ApiModel/AllowedUpdate.cs +18 -1
  22. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/ApiModel/CommitOptions.cs +8 -0
  23. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/ApiModel/Condition.cs +19 -0
  24. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/ApiModel/DependencyGroup.cs +8 -0
  25. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/ApiModel/GroupPullRequest.cs +9 -0
  26. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/ApiModel/Job.cs +13 -10
  27. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/ApiModel/PullRequest.cs +11 -0
  28. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/ApiModel/RequirementsUpdateStrategy.cs +15 -0
  29. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/RunWorker.cs +24 -4
  30. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/VersionConverter.cs +19 -0
  31. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/BindingRedirectManager.cs +2 -1
  32. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/LockFileUpdater.cs +3 -2
  33. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/PackageReferenceUpdater.cs +43 -18
  34. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/PackagesConfigUpdater.cs +13 -12
  35. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/UpdaterWorker.cs +1 -1
  36. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Utilities/JsonHelper.cs +2 -0
  37. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Utilities/MSBuildHelper.cs +40 -14
  38. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Utilities/NuGetHelper.cs +2 -2
  39. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Utilities/ProcessExtensions.cs +45 -7
  40. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Utilities/ProjectHelper.cs +2 -2
  41. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Analyze/AnalyzeWorkerTestBase.cs +5 -2
  42. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Discover/DiscoveryWorkerTests.DotNetToolsJson.cs +45 -1
  43. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Discover/DiscoveryWorkerTests.GlobalJson.cs +35 -1
  44. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Discover/DiscoveryWorkerTests.Project.cs +0 -4
  45. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Discover/DiscoveryWorkerTests.cs +41 -0
  46. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Discover/ExpectedDiscoveryResults.cs +1 -0
  47. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Discover/SdkProjectDiscoveryTests.cs +1 -1
  48. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/MockNuGetPackage.cs +2 -1
  49. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/MiscellaneousTests.cs +85 -0
  50. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/RunWorkerTests.cs +7 -31
  51. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/SerializationTests.cs +340 -0
  52. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/TemporaryDirectory.cs +18 -7
  53. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/PackagesConfigUpdaterTests.cs +24 -0
  54. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/UpdateWorkerTestBase.cs +0 -12
  55. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/UpdateWorkerTests.DotNetTools.cs +84 -0
  56. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/UpdateWorkerTests.GlobalJson.cs +66 -0
  57. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/UpdateWorkerTests.PackageReference.cs +55 -0
  58. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/UpdateWorkerTests.PackagesConfig.cs +0 -6
  59. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Utilities/MSBuildHelperTests.cs +785 -755
  60. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Utilities/PathHelperTests.cs +2 -2
  61. data/lib/dependabot/nuget/analysis/analysis_json_reader.rb +1 -1
  62. data/lib/dependabot/nuget/analysis/dependency_analysis.rb +3 -3
  63. data/lib/dependabot/nuget/discovery/dependency_details.rb +10 -3
  64. data/lib/dependabot/nuget/discovery/dependency_file_discovery.rb +8 -12
  65. data/lib/dependabot/nuget/discovery/discovery_json_reader.rb +214 -29
  66. data/lib/dependabot/nuget/discovery/project_discovery.rb +41 -8
  67. data/lib/dependabot/nuget/discovery/workspace_discovery.rb +14 -19
  68. data/lib/dependabot/nuget/file_fetcher.rb +3 -3
  69. data/lib/dependabot/nuget/file_parser.rb +92 -3
  70. data/lib/dependabot/nuget/file_updater.rb +13 -13
  71. data/lib/dependabot/nuget/language.rb +82 -0
  72. data/lib/dependabot/nuget/native_helpers.rb +37 -5
  73. data/lib/dependabot/nuget/package_manager.rb +51 -0
  74. data/lib/dependabot/nuget/update_checker/requirements_updater.rb +23 -27
  75. data/lib/dependabot/nuget/update_checker.rb +116 -190
  76. metadata +20 -29
  77. data/lib/dependabot/nuget/discovery/directory_packages_props_discovery.rb +0 -43
  78. data/lib/dependabot/nuget/http_response_helpers.rb +0 -19
  79. data/lib/dependabot/nuget/native_discovery/native_dependency_details.rb +0 -102
  80. data/lib/dependabot/nuget/native_discovery/native_dependency_file_discovery.rb +0 -122
  81. data/lib/dependabot/nuget/native_discovery/native_discovery_json_reader.rb +0 -277
  82. data/lib/dependabot/nuget/native_discovery/native_evaluation_details.rb +0 -63
  83. data/lib/dependabot/nuget/native_discovery/native_project_discovery.rb +0 -104
  84. data/lib/dependabot/nuget/native_discovery/native_property_details.rb +0 -43
  85. data/lib/dependabot/nuget/native_discovery/native_workspace_discovery.rb +0 -61
  86. data/lib/dependabot/nuget/native_update_checker/native_requirements_updater.rb +0 -105
  87. data/lib/dependabot/nuget/native_update_checker/native_update_checker.rb +0 -214
  88. data/lib/dependabot/nuget/nuget_client.rb +0 -223
  89. data/lib/dependabot/nuget/update_checker/compatibility_checker.rb +0 -116
  90. data/lib/dependabot/nuget/update_checker/dependency_finder.rb +0 -297
  91. data/lib/dependabot/nuget/update_checker/nupkg_fetcher.rb +0 -221
  92. data/lib/dependabot/nuget/update_checker/nuspec_fetcher.rb +0 -110
  93. data/lib/dependabot/nuget/update_checker/property_updater.rb +0 -196
  94. data/lib/dependabot/nuget/update_checker/repository_finder.rb +0 -466
  95. data/lib/dependabot/nuget/update_checker/tfm_comparer.rb +0 -34
  96. data/lib/dependabot/nuget/update_checker/tfm_finder.rb +0 -30
  97. data/lib/dependabot/nuget/update_checker/version_finder.rb +0 -449
@@ -1,110 +0,0 @@
1
- # typed: strict
2
- # frozen_string_literal: true
3
-
4
- require "nokogiri"
5
- require "stringio"
6
- require "sorbet-runtime"
7
- require "zip"
8
-
9
- module Dependabot
10
- module Nuget
11
- class NuspecFetcher
12
- extend T::Sig
13
-
14
- require_relative "nupkg_fetcher"
15
- require_relative "repository_finder"
16
-
17
- sig do
18
- params(
19
- dependency_urls: T::Array[T::Hash[Symbol, String]],
20
- package_id: String,
21
- package_version: T.nilable(String)
22
- )
23
- .returns(T.nilable(Nokogiri::XML::Document))
24
- end
25
- def self.fetch_nuspec(dependency_urls, package_id, package_version)
26
- # check all repositories for the first one that has the nuspec
27
- dependency_urls.reduce(T.let(nil, T.nilable(Nokogiri::XML::Document))) do |nuspec_xml, repository_details|
28
- nuspec_xml || fetch_nuspec_from_repository(repository_details, package_id, package_version)
29
- end
30
- end
31
-
32
- sig do
33
- params(
34
- repository_details: T::Hash[Symbol, T.untyped],
35
- package_id: T.nilable(String),
36
- package_version: T.nilable(String)
37
- )
38
- .returns(T.nilable(Nokogiri::XML::Document))
39
- end
40
- def self.fetch_nuspec_from_repository(repository_details, package_id, package_version)
41
- return unless package_id && package_version && !package_version.empty?
42
-
43
- feed_url = repository_details[:repository_url]
44
- auth_header = repository_details[:auth_header]
45
-
46
- nuspec_xml = nil
47
-
48
- if feed_supports_nuspec_download?(feed_url)
49
- # we can use the normal nuget apis to get the nuspec and list out the dependencies
50
- base_url = repository_details[:base_url].delete_suffix("/")
51
- package_id_downcased = package_id.downcase
52
- nuspec_url = "#{base_url}/#{package_id_downcased}/#{package_version}/#{package_id_downcased}.nuspec"
53
-
54
- nuspec_response = Dependabot::RegistryClient.get(
55
- url: nuspec_url,
56
- headers: auth_header
57
- )
58
-
59
- return unless nuspec_response.status == 200
60
-
61
- nuspec_response_body = remove_invalid_characters(nuspec_response.body)
62
- nuspec_xml = Nokogiri::XML(nuspec_response_body)
63
- else
64
- # no guarantee we can directly query the .nuspec; fall back to extracting it from the .nupkg
65
- package_data = NupkgFetcher.fetch_nupkg_buffer_from_repository(repository_details, package_id,
66
- package_version)
67
- return if package_data.nil?
68
-
69
- nuspec_string = extract_nuspec(package_data, package_id)
70
- nuspec_xml = Nokogiri::XML(nuspec_string)
71
- end
72
-
73
- nuspec_xml.remove_namespaces!
74
- nuspec_xml
75
- end
76
-
77
- sig { params(feed_url: String).returns(T::Boolean) }
78
- def self.feed_supports_nuspec_download?(feed_url)
79
- feed_regexs = [
80
- # nuget
81
- %r{https://api\.nuget\.org/v3/index\.json},
82
- # azure devops
83
- %r{https://pkgs\.dev\.azure\.com/(?<organization>[^/]+)/(?<project>[^/]+)/_packaging/(?<feedId>[^/]+)/nuget/v3/index\.json},
84
- %r{https://pkgs\.dev\.azure\.com/(?<organization>[^/]+)/_packaging/(?<feedId>[^/]+)/nuget/v3/index\.json(?<project>)},
85
- %r{https://(?<organization>[^\.\/]+)\.pkgs\.visualstudio\.com/_packaging/(?<feedId>[^/]+)/nuget/v3/index\.json(?<project>)}
86
- ]
87
- feed_regexs.any? { |reg| reg.match(feed_url) }
88
- end
89
-
90
- sig { params(zip_stream: String, package_id: String).returns(T.nilable(String)) }
91
- def self.extract_nuspec(zip_stream, package_id)
92
- Zip::File.open_buffer(zip_stream) do |zip|
93
- nuspec_entry = zip.find { |entry| entry.name == "#{package_id}.nuspec" }
94
- return nuspec_entry.get_input_stream.read if nuspec_entry
95
- end
96
- nil
97
- end
98
-
99
- sig { params(string: String).returns(String) }
100
- def self.remove_invalid_characters(string)
101
- string.dup
102
- .force_encoding(Encoding::UTF_8)
103
- .encode
104
- .scrub("")
105
- .gsub(/\A[\u200B-\u200D\uFEFF]/, "")
106
- .gsub(/[\u200B-\u200D\uFEFF]\Z/, "")
107
- end
108
- end
109
- end
110
- end
@@ -1,196 +0,0 @@
1
- # typed: strict
2
- # frozen_string_literal: true
3
-
4
- require "sorbet-runtime"
5
-
6
- require "dependabot/update_checkers/base"
7
- require "dependabot/nuget/file_parser"
8
-
9
- module Dependabot
10
- module Nuget
11
- class UpdateChecker < Dependabot::UpdateCheckers::Base
12
- class PropertyUpdater
13
- extend T::Sig
14
-
15
- require_relative "version_finder"
16
- require_relative "requirements_updater"
17
- require_relative "dependency_finder"
18
-
19
- sig do
20
- params(
21
- dependency: Dependabot::Dependency,
22
- dependency_files: T::Array[Dependabot::DependencyFile],
23
- credentials: T::Array[Dependabot::Credential],
24
- target_version_details: T.nilable(T::Hash[Symbol, String]),
25
- ignored_versions: T::Array[String],
26
- repo_contents_path: T.nilable(String),
27
- raise_on_ignored: T::Boolean
28
- ).void
29
- end
30
- def initialize(dependency:, dependency_files:, credentials:,
31
- target_version_details:, ignored_versions:,
32
- repo_contents_path:, raise_on_ignored: false)
33
- @dependency = dependency
34
- @dependency_files = dependency_files
35
- @credentials = credentials
36
- @ignored_versions = ignored_versions
37
- @raise_on_ignored = raise_on_ignored
38
- @target_version = T.let(
39
- target_version_details&.fetch(:version),
40
- T.nilable(T.any(String, Dependabot::Nuget::Version))
41
- )
42
- @source_details = T.let(
43
- target_version_details&.slice(:nuspec_url, :repo_url, :source_url),
44
- T.nilable(T::Hash[Symbol, String])
45
- )
46
- @repo_contents_path = repo_contents_path
47
- end
48
-
49
- sig { returns(T::Boolean) }
50
- def update_possible?
51
- return false unless target_version
52
-
53
- @update_possible ||= T.let(
54
- dependencies_using_property.all? do |dep|
55
- versions = VersionFinder.new(
56
- dependency: dep,
57
- dependency_files: dependency_files,
58
- credentials: credentials,
59
- ignored_versions: ignored_versions,
60
- raise_on_ignored: @raise_on_ignored,
61
- security_advisories: [],
62
- repo_contents_path: repo_contents_path
63
- ).versions.map { |v| v.fetch(:version) }
64
-
65
- versions.include?(target_version) || versions.none?
66
- end,
67
- T.nilable(T::Boolean)
68
- )
69
- end
70
-
71
- sig { returns(T::Array[Dependabot::Dependency]) }
72
- def updated_dependencies
73
- raise "Update not possible!" unless update_possible?
74
-
75
- @updated_dependencies ||= T.let(
76
- begin
77
- dependencies = T.let({}, T::Hash[String, Dependabot::Dependency])
78
-
79
- dependencies_using_property.each do |dep|
80
- # Only keep one copy of each dependency, the one with the highest target version.
81
- visited_dependency = dependencies[dep.name.downcase]
82
- next unless visited_dependency.nil? || T.must(visited_dependency.numeric_version) < target_version
83
-
84
- updated_dependency = Dependency.new(
85
- name: dep.name,
86
- version: target_version.to_s,
87
- requirements: updated_requirements(dep),
88
- previous_version: dep.version,
89
- previous_requirements: dep.requirements,
90
- package_manager: dep.package_manager
91
- )
92
- dependencies[updated_dependency.name.downcase] = updated_dependency
93
- # Add peer dependencies to the list of updated dependencies.
94
- process_updated_peer_dependencies(updated_dependency, dependencies)
95
- end
96
-
97
- dependencies.map { |_, dependency| dependency }
98
- end,
99
- T.nilable(T::Array[Dependabot::Dependency])
100
- )
101
- end
102
-
103
- private
104
-
105
- sig { returns(Dependabot::Dependency) }
106
- attr_reader :dependency
107
-
108
- sig { returns(T::Array[Dependabot::DependencyFile]) }
109
- attr_reader :dependency_files
110
-
111
- sig { returns(T.nilable(T.any(String, Dependabot::Nuget::Version))) }
112
- attr_reader :target_version
113
-
114
- sig { returns(T.nilable(T::Hash[Symbol, String])) }
115
- attr_reader :source_details
116
-
117
- sig { returns(T::Array[Dependabot::Credential]) }
118
- attr_reader :credentials
119
-
120
- sig { returns(T::Array[String]) }
121
- attr_reader :ignored_versions
122
-
123
- sig { returns(T.nilable(String)) }
124
- attr_reader :repo_contents_path
125
-
126
- sig do
127
- params(
128
- dependency: Dependabot::Dependency,
129
- dependencies: T::Hash[String, Dependabot::Dependency]
130
- )
131
- .returns(T::Array[Dependabot::Dependency])
132
- end
133
- def process_updated_peer_dependencies(dependency, dependencies)
134
- DependencyFinder.new(
135
- dependency: dependency,
136
- dependency_files: dependency_files,
137
- ignored_versions: ignored_versions,
138
- credentials: credentials,
139
- repo_contents_path: repo_contents_path
140
- ).updated_peer_dependencies.each do |peer_dependency|
141
- # Only keep one copy of each dependency, the one with the highest target version.
142
- visited_dependency = dependencies[peer_dependency.name.downcase]
143
- unless visited_dependency.nil? ||
144
- T.must(visited_dependency.numeric_version) < peer_dependency.numeric_version
145
- next
146
- end
147
-
148
- dependencies[peer_dependency.name.downcase] = peer_dependency
149
- end
150
- end
151
-
152
- sig { returns(T::Array[Dependabot::Dependency]) }
153
- def dependencies_using_property
154
- @dependencies_using_property ||=
155
- T.let(
156
- Nuget::FileParser.new(
157
- dependency_files: dependency_files,
158
- repo_contents_path: repo_contents_path,
159
- source: nil
160
- ).parse.select do |dep|
161
- dep.requirements.any? do |r|
162
- r.dig(:metadata, :property_name) == property_name
163
- end
164
- end,
165
- T.nilable(T::Array[Dependabot::Dependency])
166
- )
167
- end
168
-
169
- sig { returns(String) }
170
- def property_name
171
- @property_name ||= T.let(
172
- dependency.requirements
173
- .find { |r| r.dig(:metadata, :property_name) }
174
- &.dig(:metadata, :property_name),
175
- T.nilable(String)
176
- )
177
-
178
- raise "No requirement with a property name!" unless @property_name
179
-
180
- @property_name
181
- end
182
-
183
- sig { params(dep: Dependabot::Dependency).returns(T::Array[T::Hash[Symbol, T.untyped]]) }
184
- def updated_requirements(dep)
185
- @updated_requirements ||= T.let({}, T.nilable(T::Hash[String, T::Array[T::Hash[Symbol, T.untyped]]]))
186
- @updated_requirements[dep.name] ||=
187
- RequirementsUpdater.new(
188
- requirements: dep.requirements,
189
- latest_version: target_version,
190
- source_details: source_details
191
- ).updated_requirements
192
- end
193
- end
194
- end
195
- end
196
- end