dependabot-nuget 0.242.0 → 0.243.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/helpers/lib/NuGetUpdater/.editorconfig +37 -28
  3. data/helpers/lib/NuGetUpdater/.gitignore +1 -0
  4. data/helpers/lib/NuGetUpdater/NuGetProjects/NuGet.CommandLine/AssemblyMetadataExtractor.cs +2 -1
  5. data/helpers/lib/NuGetUpdater/NuGetUpdater.Cli/Program.cs +2 -2
  6. data/helpers/lib/NuGetUpdater/NuGetUpdater.Cli.Test/EntryPointTests.Update.cs +178 -176
  7. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Files/JsonBuildFile.cs +2 -1
  8. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Files/PackagesConfigBuildFile.cs +1 -0
  9. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Files/ProjectBuildFile.cs +5 -4
  10. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/FrameworkChecker/CompatabilityChecker.cs +1 -0
  11. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/FrameworkChecker/FrameworkCompatibilityService.cs +10 -5
  12. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/FrameworkChecker/SupportedFrameworks.cs +16 -12
  13. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/BindingRedirectManager.cs +18 -17
  14. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/BindingRedirectResolver.cs +7 -7
  15. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/DotNetToolsJsonUpdater.cs +13 -20
  16. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/GlobalJsonUpdater.cs +9 -3
  17. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/PackagesConfigUpdater.cs +32 -16
  18. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/SdkPackageUpdater.cs +42 -22
  19. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/UpdaterWorker.cs +32 -13
  20. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/WebApplicationTargetsConditionPatcher.cs +47 -0
  21. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/XmlFilePreAndPostProcessor.cs +55 -0
  22. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Utilities/JsonHelper.cs +12 -9
  23. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Utilities/MSBuildHelper.cs +50 -42
  24. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Utilities/PathHelper.cs +16 -3
  25. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Utilities/ProcessExtensions.cs +6 -6
  26. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Utilities/XmlExtensions.cs +11 -0
  27. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Files/ProjectBuildFileTests.cs +18 -9
  28. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/FrameworkChecker/CompatibilityCheckerFacts.cs +2 -2
  29. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/FrameworkChecker/FrameworkCompatibilityServiceFacts.cs +7 -7
  30. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/FrameworkChecker/SupportedFrameworkFacts.cs +1 -1
  31. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/PackagesConfigUpdaterTests.cs +9 -9
  32. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/UpdateWorker.DirsProj.cs +81 -80
  33. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/UpdateWorkerTestBase.cs +22 -9
  34. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/UpdateWorkerTests.DotNetTools.cs +140 -104
  35. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/UpdateWorkerTests.GlobalJson.cs +25 -25
  36. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/UpdateWorkerTests.Mixed.cs +8 -9
  37. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/UpdateWorkerTests.PackagesConfig.cs +198 -22
  38. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/UpdateWorkerTests.Sdk.cs +401 -399
  39. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Utilities/JsonHelperTests.cs +17 -15
  40. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Utilities/MSBuildHelperTests.cs +111 -42
  41. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Utilities/SdkPackageUpdaterTests.cs +161 -82
  42. data/lib/dependabot/nuget/file_fetcher.rb +3 -23
  43. data/lib/dependabot/nuget/file_parser/project_file_parser.rb +47 -60
  44. data/lib/dependabot/nuget/file_parser.rb +24 -6
  45. data/lib/dependabot/nuget/file_updater.rb +42 -6
  46. data/lib/dependabot/nuget/native_helpers.rb +27 -8
  47. data/lib/dependabot/nuget/nuget_client.rb +130 -24
  48. data/lib/dependabot/nuget/nuget_config_credential_helpers.rb +7 -3
  49. data/lib/dependabot/nuget/update_checker/compatibility_checker.rb +63 -59
  50. data/lib/dependabot/nuget/update_checker/dependency_finder.rb +2 -2
  51. data/lib/dependabot/nuget/update_checker/nupkg_fetcher.rb +1 -1
  52. data/lib/dependabot/nuget/update_checker/nuspec_fetcher.rb +22 -17
  53. data/lib/dependabot/nuget/update_checker/repository_finder.rb +292 -270
  54. data/lib/dependabot/nuget/update_checker/tfm_comparer.rb +11 -13
  55. data/lib/dependabot/nuget/update_checker/tfm_finder.rb +80 -82
  56. data/lib/dependabot/nuget/update_checker/version_finder.rb +4 -7
  57. data/lib/dependabot/nuget/version.rb +18 -7
  58. data/lib/dependabot/nuget.rb +0 -2
  59. metadata +7 -5
@@ -12,115 +12,113 @@ require "dependabot/shared_helpers"
12
12
 
13
13
  module Dependabot
14
14
  module Nuget
15
- class UpdateChecker < Dependabot::UpdateCheckers::Base
16
- class TfmFinder
17
- require "dependabot/nuget/file_parser/packages_config_parser"
18
- require "dependabot/nuget/file_parser/project_file_parser"
19
-
20
- def initialize(dependency_files:, credentials:)
21
- @dependency_files = dependency_files
22
- @credentials = credentials
23
- end
15
+ class TfmFinder
16
+ require "dependabot/nuget/file_parser/packages_config_parser"
17
+ require "dependabot/nuget/file_parser/project_file_parser"
24
18
 
25
- def frameworks(dependency)
26
- tfms = Set.new
27
- tfms += project_file_tfms(dependency)
28
- tfms += project_import_file_tfms
29
- tfms.to_a
30
- end
19
+ def initialize(dependency_files:, credentials:)
20
+ @dependency_files = dependency_files
21
+ @credentials = credentials
22
+ end
31
23
 
32
- private
24
+ def frameworks(dependency)
25
+ tfms = Set.new
26
+ tfms += project_file_tfms(dependency)
27
+ tfms += project_import_file_tfms
28
+ tfms.to_a
29
+ end
30
+
31
+ private
33
32
 
34
- attr_reader :dependency_files, :credentials
33
+ attr_reader :dependency_files, :credentials
35
34
 
36
- def project_file_tfms(dependency)
37
- project_files_with_dependency(dependency).flat_map do |file|
38
- project_file_parser.target_frameworks(project_file: file)
39
- end
35
+ def project_file_tfms(dependency)
36
+ project_files_with_dependency(dependency).flat_map do |file|
37
+ project_file_parser.target_frameworks(project_file: file)
40
38
  end
39
+ end
41
40
 
42
- def project_files_with_dependency(dependency)
43
- project_files.select do |file|
44
- packages_config_contains_dependency?(file, dependency) ||
45
- project_file_contains_dependency?(file, dependency)
46
- end
41
+ def project_files_with_dependency(dependency)
42
+ project_files.select do |file|
43
+ packages_config_contains_dependency?(file, dependency) ||
44
+ project_file_contains_dependency?(file, dependency)
47
45
  end
46
+ end
48
47
 
49
- def packages_config_contains_dependency?(file, dependency)
50
- config_file = find_packages_config_file(file)
51
- return false unless config_file
48
+ def packages_config_contains_dependency?(file, dependency)
49
+ config_file = find_packages_config_file(file)
50
+ return false unless config_file
52
51
 
53
- config_parser = FileParser::PackagesConfigParser.new(packages_config: config_file)
54
- config_parser.dependency_set.dependencies.any? do |d|
55
- d.name.casecmp(dependency.name).zero?
56
- end
52
+ config_parser = FileParser::PackagesConfigParser.new(packages_config: config_file)
53
+ config_parser.dependency_set.dependencies.any? do |d|
54
+ d.name.casecmp(dependency.name).zero?
57
55
  end
56
+ end
58
57
 
59
- def project_file_contains_dependency?(file, dependency)
60
- project_file_parser.dependency_set(project_file: file).dependencies.any? do |d|
61
- d.name.casecmp(dependency.name).zero?
62
- end
58
+ def project_file_contains_dependency?(file, dependency)
59
+ project_file_parser.dependency_set(project_file: file).dependencies.any? do |d|
60
+ d.name.casecmp(dependency.name).zero?
63
61
  end
62
+ end
64
63
 
65
- def find_packages_config_file(file)
66
- return file if file.name.end_with?("packages.config")
64
+ def find_packages_config_file(file)
65
+ return file if file.name.end_with?("packages.config")
67
66
 
68
- filename = File.basename(file.name)
69
- search_path = file.name.sub(filename, "packages.config")
67
+ filename = File.basename(file.name)
68
+ search_path = file.name.sub(filename, "packages.config")
70
69
 
71
- dependency_files.find { |f| f.name.casecmp(search_path).zero? }
72
- end
70
+ dependency_files.find { |f| f.name.casecmp(search_path).zero? }
71
+ end
73
72
 
74
- def project_import_file_tfms
75
- @project_import_file_tfms ||= project_import_files.flat_map do |file|
76
- project_file_parser.target_frameworks(project_file: file)
77
- end
73
+ def project_import_file_tfms
74
+ @project_import_file_tfms ||= project_import_files.flat_map do |file|
75
+ project_file_parser.target_frameworks(project_file: file)
78
76
  end
77
+ end
79
78
 
80
- def project_file_parser
81
- @project_file_parser ||=
82
- FileParser::ProjectFileParser.new(
83
- dependency_files: dependency_files,
84
- credentials: credentials
85
- )
86
- end
79
+ def project_file_parser
80
+ @project_file_parser ||=
81
+ FileParser::ProjectFileParser.new(
82
+ dependency_files: dependency_files,
83
+ credentials: credentials
84
+ )
85
+ end
87
86
 
88
- def project_files
89
- projfile = /\.[a-z]{2}proj$/
90
- packageprops = /[Dd]irectory.[Pp]ackages.props/
87
+ def project_files
88
+ projfile = /\.[a-z]{2}proj$/
89
+ packageprops = /[Dd]irectory.[Pp]ackages.props/
91
90
 
92
- dependency_files.select do |df|
93
- df.name.match?(projfile) ||
94
- df.name.match?(packageprops)
95
- end
91
+ dependency_files.select do |df|
92
+ df.name.match?(projfile) ||
93
+ df.name.match?(packageprops)
96
94
  end
95
+ end
97
96
 
98
- def packages_config_files
99
- dependency_files.select do |f|
100
- f.name.split("/").last.casecmp("packages.config").zero?
101
- end
97
+ def packages_config_files
98
+ dependency_files.select do |f|
99
+ f.name.split("/").last.casecmp("packages.config").zero?
102
100
  end
101
+ end
103
102
 
104
- def project_import_files
105
- dependency_files -
106
- project_files -
107
- packages_config_files -
108
- nuget_configs -
109
- [global_json] -
110
- [dotnet_tools_json]
111
- end
103
+ def project_import_files
104
+ dependency_files -
105
+ project_files -
106
+ packages_config_files -
107
+ nuget_configs -
108
+ [global_json] -
109
+ [dotnet_tools_json]
110
+ end
112
111
 
113
- def nuget_configs
114
- dependency_files.select { |f| f.name.match?(/nuget\.config$/i) }
115
- end
112
+ def nuget_configs
113
+ dependency_files.select { |f| f.name.match?(/nuget\.config$/i) }
114
+ end
116
115
 
117
- def global_json
118
- dependency_files.find { |f| f.name.casecmp("global.json").zero? }
119
- end
116
+ def global_json
117
+ dependency_files.find { |f| f.name.casecmp("global.json").zero? }
118
+ end
120
119
 
121
- def dotnet_tools_json
122
- dependency_files.find { |f| f.name.casecmp(".config/dotnet-tools.json").zero? }
123
- end
120
+ def dotnet_tools_json
121
+ dependency_files.find { |f| f.name.casecmp(".config/dotnet-tools.json").zero? }
124
122
  end
125
123
  end
126
124
  end
@@ -81,9 +81,10 @@ module Dependabot
81
81
  # If the current package version is incompatible, then we don't enforce compatibility.
82
82
  # It could appear incompatible because they are ignoring NU1701 or the package is poorly authored.
83
83
  return first_version unless version_compatible?(dependency.version)
84
- return first_version if version_compatible?(first_version.fetch(:version))
85
84
 
86
- sorted_versions.bsearch { |v| version_compatible?(v.fetch(:version)) }
85
+ # once sorted by version, the best we can do is search every package, because it's entirely possible for there
86
+ # to be incompatible packages both with a higher and lower version number, so no smart searching can be done.
87
+ sorted_versions.find { |v| version_compatible?(v.fetch(:version)) }
87
88
  end
88
89
 
89
90
  def version_compatible?(version)
@@ -235,7 +236,7 @@ module Dependabot
235
236
  dependency_urls
236
237
  .select { |details| details.fetch(:repository_type) == "v3" }
237
238
  .filter_map do |url_details|
238
- versions = versions_for_v3_repository(url_details)
239
+ versions = NugetClient.get_package_versions(dependency.name, url_details)
239
240
  next unless versions
240
241
 
241
242
  { "versions" => versions, "listing_details" => url_details }
@@ -294,10 +295,6 @@ module Dependabot
294
295
  nil
295
296
  end
296
297
 
297
- def versions_for_v3_repository(repository_details)
298
- NugetClient.get_package_versions_v3(dependency.name, repository_details)
299
- end
300
-
301
298
  def dependency_urls
302
299
  @dependency_urls ||=
303
300
  RepositoryFinder.new(
@@ -1,8 +1,9 @@
1
- # typed: true
1
+ # typed: strong
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require "dependabot/version"
5
5
  require "dependabot/utils"
6
+ require "sorbet-runtime"
6
7
 
7
8
  # Dotnet pre-release versions use 1.0.1-rc1 syntax, which Gem::Version
8
9
  # converts into 1.0.1.pre.rc1. We override the `to_s` method to stop that
@@ -11,30 +12,37 @@ require "dependabot/utils"
11
12
  module Dependabot
12
13
  module Nuget
13
14
  class Version < Dependabot::Version
14
- VERSION_PATTERN = Gem::Version::VERSION_PATTERN + '(\+[0-9a-zA-Z\-.]+)?'
15
+ extend T::Sig
16
+
17
+ VERSION_PATTERN = T.let(Gem::Version::VERSION_PATTERN + '(\+[0-9a-zA-Z\-.]+)?', String)
15
18
  ANCHORED_VERSION_PATTERN = /\A\s*(#{VERSION_PATTERN})?\s*\z/
16
19
 
20
+ sig { override.params(version: T.nilable(T.any(String, Integer, Float, Gem::Version))).returns(T::Boolean) }
17
21
  def self.correct?(version)
18
22
  return false if version.nil?
19
23
 
20
24
  version.to_s.match?(ANCHORED_VERSION_PATTERN)
21
25
  end
22
26
 
27
+ sig { override.params(version: T.nilable(T.any(String, Integer, Float, Gem::Version))).void }
23
28
  def initialize(version)
24
29
  version = version.to_s.split("+").first || ""
25
- @version_string = version
30
+ @version_string = T.let(version, String)
26
31
 
27
32
  super
28
33
  end
29
34
 
35
+ sig { returns(String) }
30
36
  def to_s
31
37
  @version_string
32
38
  end
33
39
 
40
+ sig { returns(String) }
34
41
  def inspect # :nodoc:
35
42
  "#<#{self.class} #{@version_string}>"
36
43
  end
37
44
 
45
+ sig { params(other: Object).returns(Integer) }
38
46
  def <=>(other)
39
47
  version_comparison = compare_release(other)
40
48
  return version_comparison unless version_comparison.zero?
@@ -42,14 +50,16 @@ module Dependabot
42
50
  compare_prerelease_part(other)
43
51
  end
44
52
 
53
+ sig { params(other: Object).returns(Integer) }
45
54
  def compare_release(other)
46
55
  release_str = @version_string.split("-").first || ""
47
56
  other_release_str = other.to_s.split("-").first || ""
48
57
 
49
- Gem::Version.new(release_str) <=> Gem::Version.new(other_release_str)
58
+ T.must(Gem::Version.new(release_str) <=> Gem::Version.new(other_release_str))
50
59
  end
51
60
 
52
61
  # rubocop:disable Metrics/PerceivedComplexity
62
+ sig { params(other: Object).returns(Integer) }
53
63
  def compare_prerelease_part(other)
54
64
  release_str = @version_string.split("-").first || ""
55
65
  prerelease_string = @version_string
@@ -67,8 +77,8 @@ module Dependabot
67
77
  return 1 if !prerelease_string && other_prerelease_string
68
78
  return 0 if !prerelease_string && !other_prerelease_string
69
79
 
70
- split_prerelease_string = prerelease_string.split(".")
71
- other_split_prerelease_string = other_prerelease_string.split(".")
80
+ split_prerelease_string = T.must(prerelease_string).split(".")
81
+ other_split_prerelease_string = T.must(other_prerelease_string).split(".")
72
82
 
73
83
  length = [split_prerelease_string.length, other_split_prerelease_string.length].max - 1
74
84
  (0..length).to_a.each do |index|
@@ -82,13 +92,14 @@ module Dependabot
82
92
  end
83
93
  # rubocop:enable Metrics/PerceivedComplexity
84
94
 
95
+ sig { params(lhs: T.nilable(String), rhs: T.nilable(String)).returns(Integer) }
85
96
  def compare_dot_separated_part(lhs, rhs)
86
97
  return -1 if lhs.nil?
87
98
  return 1 if rhs.nil?
88
99
 
89
100
  return lhs.to_i <=> rhs.to_i if lhs.match?(/^\d+$/) && rhs.match?(/^\d+$/)
90
101
 
91
- lhs.upcase <=> rhs.upcase
102
+ T.must(lhs.upcase <=> rhs.upcase)
92
103
  end
93
104
  end
94
105
  end
@@ -24,5 +24,3 @@ Dependabot::Dependency.register_production_check(
24
24
  groups.include?("dependencies")
25
25
  end
26
26
  )
27
-
28
- Dependabot::Utils.register_always_clone("nuget")
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dependabot-nuget
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.242.0
4
+ version: 0.243.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dependabot
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-01-22 00:00:00.000000000 Z
11
+ date: 2024-02-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dependabot-common
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 0.242.0
19
+ version: 0.243.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 0.242.0
26
+ version: 0.243.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rubyzip
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -325,6 +325,8 @@ files:
325
325
  - helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/SdkPackageUpdater.cs
326
326
  - helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/UpdateResult.cs
327
327
  - helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/UpdaterWorker.cs
328
+ - helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/WebApplicationTargetsConditionPatcher.cs
329
+ - helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/XmlFilePreAndPostProcessor.cs
328
330
  - helpers/lib/NuGetUpdater/NuGetUpdater.Core/Utilities/JsonHelper.cs
329
331
  - helpers/lib/NuGetUpdater/NuGetUpdater.Core/Utilities/Logger.cs
330
332
  - helpers/lib/NuGetUpdater/NuGetUpdater.Core/Utilities/MSBuildHelper.cs
@@ -369,7 +371,7 @@ licenses:
369
371
  - Nonstandard
370
372
  metadata:
371
373
  bug_tracker_uri: https://github.com/dependabot/dependabot-core/issues
372
- changelog_uri: https://github.com/dependabot/dependabot-core/releases/tag/v0.242.0
374
+ changelog_uri: https://github.com/dependabot/dependabot-core/releases/tag/v0.243.0
373
375
  post_install_message:
374
376
  rdoc_options: []
375
377
  require_paths: