dependabot-cargo 0.391.0 → 0.392.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '05078f5575e3921c69b7c00b73064f0e2a49992c0296b6fabfcb1ac0ea8fc9e9'
4
- data.tar.gz: 9b1f99e9db2b5534f35abef47de2762a3e9e209e9f48f4723c1277b3b1369046
3
+ metadata.gz: 45898e2e894023fb481da89044263d6f4a3e6791719c40cc1413815ed5d3abf2
4
+ data.tar.gz: bd691e2c7daf7172a83dc39929e6cedd5e221b57edaac7b83b52d54e3235956a
5
5
  SHA512:
6
- metadata.gz: d8ec56f6721d1322f29d426ccef73f17cdb4c9ba586633ea81e31a5f20853437d50e5cbf62fc1b85fbf4bf0d3fe30f8d0916d0b5c327ccac1391d70d428982dc
7
- data.tar.gz: 26a80a7d0d5381a61293990a10768b7960bf97544a8df163ec65b2dc96c9cbfc66aa0c311107428f5e9af65e7f69889a185def6ef7b4244ecdd51f31da7ae6c9
6
+ metadata.gz: 6baf89c602bf3f9585415500d7020d6fa6b2437e87e51c0c8a94beca3bca91a7cbc09d8504449b8126a86b933e5b43413d70ead886377aaff3b2df5dde805c55
7
+ data.tar.gz: c19750334737189611ae01268d90bd0e3c759e64004ba2aad9acf25e6974f816fa3dd3a2640bb7898275aa42d09815429e737ddfe2621364d8f8e910f1382573
@@ -42,7 +42,7 @@ module Dependabot
42
42
  # TODO: Currently, Dependabot can't handle dependencies that have
43
43
  # multiple sources. Fix that!
44
44
  dependencies.reject do |dep|
45
- dep.requirements.map { |r| r.fetch(:source) }.uniq.count > 1
45
+ dep.requirements.map(&:source).uniq.count > 1
46
46
  end
47
47
  end
48
48
 
@@ -255,8 +255,8 @@ module Dependabot
255
255
  sig { returns(T.nilable(String)) }
256
256
  def git_source_url
257
257
  dependency.previous_requirements
258
- &.find { |r| r.dig(:source, :type) == "git" }
259
- &.dig(:source, :url)
258
+ &.find { |r| r.source_string("type") == "git" }
259
+ &.source_string("url")
260
260
  end
261
261
 
262
262
  sig { returns(String) }
@@ -779,9 +779,9 @@ module Dependabot
779
779
  # only when no current git source exists.
780
780
  sig { params(key: Symbol).returns(T.nilable(String)) }
781
781
  def git_source_detail(key)
782
- source = dependency.requirements.find { |r| r.dig(:source, :type) == "git" }&.dig(:source) ||
783
- dependency.previous_requirements&.find { |r| r.dig(:source, :type) == "git" }&.dig(:source)
784
- source&.dig(key)
782
+ requirement = dependency.requirements.find { |r| r.source_string("type") == "git" } ||
783
+ dependency.previous_requirements&.find { |r| r.source_string("type") == "git" }
784
+ requirement&.source_string(key.to_s)
785
785
  end
786
786
 
787
787
  sig do
@@ -1,4 +1,4 @@
1
- # typed: strict
1
+ # typed: strong
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require "sorbet-runtime"
@@ -65,7 +65,7 @@ module Dependabot
65
65
  changed_requirements =
66
66
  dependency.requirements - (dependency.previous_requirements || [])
67
67
 
68
- changed_requirements.any? { |f| f[:file] == file.name }
68
+ changed_requirements.any? { |requirement| requirement.file == file.name }
69
69
  end
70
70
 
71
71
  sig { params(content: String, filename: String, dependency: Dependabot::Dependency).returns(String) }
@@ -82,16 +82,16 @@ module Dependabot
82
82
  reqs.each do |new_req, old_req|
83
83
  next if old_req.nil?
84
84
 
85
- raise "Bad req match" unless new_req[:file] == old_req[:file]
86
- next if new_req[:requirement] == old_req[:requirement]
87
- next unless new_req[:file] == filename
85
+ raise "Bad req match" unless new_req.file == old_req.file
86
+ next if new_req.requirement == old_req.requirement
87
+ next unless new_req.file == filename
88
88
 
89
89
  updated_content =
90
90
  update_manifest_req(
91
91
  content: updated_content,
92
92
  dep: dependency,
93
- old_req: old_req.fetch(:requirement),
94
- new_req: new_req.fetch(:requirement)
93
+ old_req: T.must(old_req.requirement_string),
94
+ new_req: T.must(new_req.requirement_string)
95
95
  )
96
96
  end
97
97
 
@@ -102,13 +102,13 @@ module Dependabot
102
102
  def update_git_pin(content:, filename:, dependency:)
103
103
  updated_pin =
104
104
  dependency.requirements
105
- .find { |r| r[:file] == filename }
106
- &.dig(:source, :ref)
105
+ .find { |r| r.file == filename }
106
+ &.source_string("ref")
107
107
 
108
108
  old_pin =
109
109
  dependency.previous_requirements
110
- &.find { |r| r[:file] == filename }
111
- &.dig(:source, :ref)
110
+ &.find { |r| r.file == filename }
111
+ &.source_string("ref")
112
112
 
113
113
  return content unless old_pin
114
114
 
@@ -116,7 +116,7 @@ module Dependabot
116
116
  content: content,
117
117
  dep: dependency,
118
118
  old_pin: old_pin,
119
- new_pin: updated_pin
119
+ new_pin: T.must(updated_pin)
120
120
  )
121
121
  end
122
122
 
@@ -1,4 +1,4 @@
1
- # typed: strict
1
+ # typed: strong
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require "sorbet-runtime"
@@ -39,7 +39,7 @@ module Dependabot
39
39
 
40
40
  sig { params(dep: Dependabot::Dependency).returns(T::Boolean) }
41
41
  def workspace_dependency?(dep)
42
- dep.requirements.any? { |r| r[:groups]&.include?("workspace.dependencies") }
42
+ dep.requirements.any? { |r| r.groups&.include?("workspace.dependencies") }
43
43
  end
44
44
 
45
45
  sig { params(content: String, dep: Dependabot::Dependency).returns(String) }
@@ -66,8 +66,8 @@ module Dependabot
66
66
 
67
67
  sig { params(requirements: T.nilable(T::Array[Dependabot::DependencyRequirement])).returns(T.nilable(String)) }
68
68
  def find_workspace_requirement(requirements)
69
- requirements&.find { |r| r[:groups]&.include?("workspace.dependencies") }
70
- &.fetch(:requirement)
69
+ requirements&.find { |r| r.groups&.include?("workspace.dependencies") }
70
+ &.requirement_string
71
71
  end
72
72
 
73
73
  sig { params(section: String, dep_name: String, old_req: String, new_req: String).returns(String) }
@@ -54,26 +54,15 @@ module Dependabot
54
54
 
55
55
  sig { returns(T.nilable(Dependabot::Source)) }
56
56
  def find_source_from_git_url
57
- info = T.cast(
58
- dependency.requirements.filter_map { |r| r[:source] }.first,
59
- T.nilable(T::Hash[T.any(String, Symbol), T.anything])
60
- )
61
- return unless info
62
-
63
- url = info[:url] || info["url"]
64
- Source.from_url(T.cast(url, T.nilable(String)))
57
+ Source.from_url(dependency.source_string("url", allowed_types: ["git"]))
65
58
  end
66
59
 
67
60
  sig { returns(T.nilable(T::Hash[String, T.anything])) }
68
61
  def crates_listing
69
62
  return @crates_listing unless @crates_listing.nil?
70
63
 
71
- info = T.cast(
72
- dependency.requirements.filter_map { |r| r[:source] }.first,
73
- T.nilable(T::Hash[T.any(String, Symbol), T.anything])
74
- )
75
- index = T.cast((info && (info[:index] || info["index"])) || CRATES_IO_API, String)
76
- hdrs = build_headers(index, info)
64
+ index = dependency.source_string("index") || CRATES_IO_API
65
+ hdrs = build_headers(index, dependency.source_string("name"))
77
66
 
78
67
  url = metadata_fetch_url(dependency, index)
79
68
  response = fetch_metadata(url, hdrs)
@@ -82,16 +71,14 @@ module Dependabot
82
71
  end
83
72
 
84
73
  sig do
85
- params(index: String, info: T.nilable(T::Hash[T.any(String, Symbol), T.anything]))
74
+ params(index: String, registry_name: T.nilable(String))
86
75
  .returns(T::Hash[String, String])
87
76
  end
88
- def build_headers(index, info)
77
+ def build_headers(index, registry_name)
89
78
  hdrs = { "User-Agent" => "Dependabot (dependabot.com)" }
90
79
  return hdrs if index == CRATES_IO_API
80
+ return hdrs if registry_name.nil?
91
81
 
92
- return hdrs if info.nil?
93
-
94
- registry_name = T.cast(info["name"] || info[:name], T.nilable(String))
95
82
  credentials.find { |cred| cred["type"] == "cargo_registry" && cred["registry"] == registry_name }&.tap do |cred|
96
83
  hdrs["Authorization"] = "Token #{cred['token']}"
97
84
  end
@@ -75,11 +75,10 @@ module Dependabot
75
75
  def crates_listing
76
76
  return @crates_listing unless @crates_listing.nil?
77
77
 
78
- info = fetch_dependency_info
79
- index = fetch_index(info)
78
+ index = fetch_index
80
79
 
81
80
  hdrs = default_headers
82
- hdrs.merge!(auth_headers(info)) if index != CRATES_IO_API
81
+ hdrs.merge!(auth_headers) if index != CRATES_IO_API
83
82
 
84
83
  url = metadata_fetch_url(dependency, index)
85
84
 
@@ -95,17 +94,9 @@ module Dependabot
95
94
  T.must(@crates_listing)
96
95
  end
97
96
 
98
- sig { returns(T.nilable(T::Hash[T.any(String, Symbol), T.anything])) }
99
- def fetch_dependency_info
100
- T.cast(
101
- dependency.requirements.filter_map { |r| r[:source] }.first,
102
- T.nilable(T::Hash[T.any(String, Symbol), T.anything])
103
- )
104
- end
105
-
106
- sig { params(info: T.nilable(T::Hash[T.any(String, Symbol), T.anything])).returns(String) }
107
- def fetch_index(info)
108
- T.cast((info && (info[:index] || info["index"])) || CRATES_IO_API, String)
97
+ sig { returns(String) }
98
+ def fetch_index
99
+ dependency.source_string("index") || CRATES_IO_API
109
100
  end
110
101
 
111
102
  sig { returns(T::Hash[String, String]) }
@@ -113,9 +104,9 @@ module Dependabot
113
104
  { "User-Agent" => "Dependabot (dependabot.com)" }
114
105
  end
115
106
 
116
- sig { params(info: T.nilable(T::Hash[T.any(String, Symbol), T.anything])).returns(T::Hash[String, String]) }
117
- def auth_headers(info)
118
- registry_name = T.cast(info && (info[:name] || info["name"]), T.nilable(String))
107
+ sig { returns(T::Hash[String, String]) }
108
+ def auth_headers
109
+ registry_name = dependency.source_string("name")
119
110
  registry_creds = credentials.find do |cred|
120
111
  cred["type"] == "cargo_registry" && cred["registry"] == registry_name
121
112
  end
@@ -178,7 +169,7 @@ module Dependabot
178
169
  return true if dependency.numeric_version&.prerelease?
179
170
 
180
171
  dependency.requirements.any? do |req|
181
- reqs = (req.fetch(:requirement) || "").split(",").map(&:strip)
172
+ reqs = (req.requirement_string || "").split(",").map(&:strip)
182
173
  reqs.any? { |r| r.match?(/[A-Za-z]/) }
183
174
  end
184
175
  end
@@ -238,8 +238,8 @@ module Dependabot
238
238
  sig { params(filename: String).returns(String) }
239
239
  def temporary_requirement_for_resolution(filename)
240
240
  original_req = dependency.requirements
241
- .find { |r| r.fetch(:file) == filename }
242
- &.fetch(:requirement)
241
+ .find { |r| r.file == filename }
242
+ &.requirement_string
243
243
 
244
244
  lower_bound_req =
245
245
  if original_req && !unlock_requirement?
@@ -268,11 +268,12 @@ module Dependabot
268
268
  dependency.version
269
269
  else
270
270
  version_from_requirement =
271
- dependency.requirements.filter_map { |r| r.fetch(:requirement) }
272
- .flat_map { |req_str| Cargo::Requirement.new(req_str) }
273
- .flat_map(&:requirements)
274
- .reject { |req_array| req_array.first.start_with?("<") }
275
- .map(&:last)
271
+ dependency.requirements
272
+ .filter_map(&:requirement_string)
273
+ .flat_map { |req_str| Cargo::Requirement.new(req_str) }
274
+ .flat_map(&:requirements)
275
+ .reject { |req_array| req_array.first.start_with?("<") }
276
+ .map(&:last)
276
277
  .max&.to_s
277
278
 
278
279
  version_from_requirement || 0
@@ -1,4 +1,4 @@
1
- # typed: strict
1
+ # typed: strong
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require "excon"
@@ -49,7 +49,7 @@ module Dependabot
49
49
  return true if dependency.numeric_version&.prerelease?
50
50
 
51
51
  dependency.requirements.any? do |req|
52
- reqs = (req.fetch(:requirement) || "").split(",").map(&:strip)
52
+ reqs = (req.requirement_string || "").split(",").map(&:strip)
53
53
  reqs.any? { |r| r.match?(/[A-Za-z]/) }
54
54
  end
55
55
  end
@@ -36,7 +36,7 @@ module Dependabot
36
36
  sig do
37
37
  params(
38
38
  requirements: T::Array[Dependabot::DependencyRequirement],
39
- updated_source: T.nilable(T::Hash[T.any(String, Symbol), T.anything]),
39
+ updated_source: T.nilable(Dependabot::DependencyRequirement::ObjectHash),
40
40
  update_strategy: Dependabot::RequirementsUpdateStrategy,
41
41
  target_version: T.nilable(T.any(String, Gem::Version))
42
42
  ).void
@@ -71,7 +71,7 @@ module Dependabot
71
71
  requirements.map do |req|
72
72
  req = Dependabot::DependencyRequirement.create(req.merge(source: updated_source))
73
73
  next req unless target_version
74
- next req if req[:requirement].nil?
74
+ next req if req.requirement.nil?
75
75
 
76
76
  # TODO: Add a RequirementsUpdateStrategy::WidenRanges options
77
77
  if update_strategy == Dependabot::RequirementsUpdateStrategy::BumpVersionsIfNecessary
@@ -87,7 +87,7 @@ module Dependabot
87
87
  sig { returns(T::Array[Dependabot::DependencyRequirement]) }
88
88
  attr_reader :requirements
89
89
 
90
- sig { returns(T.nilable(T::Hash[T.any(String, Symbol), T.anything])) }
90
+ sig { returns(T.nilable(Dependabot::DependencyRequirement::ObjectHash)) }
91
91
  attr_reader :updated_source
92
92
 
93
93
  sig { returns(Dependabot::RequirementsUpdateStrategy) }
@@ -105,7 +105,7 @@ module Dependabot
105
105
 
106
106
  sig { params(req: Dependabot::DependencyRequirement).returns(Dependabot::DependencyRequirement) }
107
107
  def update_version_requirement(req)
108
- string_reqs = req[:requirement].split(",").map(&:strip)
108
+ string_reqs = T.must(req.requirement_string).split(",").map(&:strip)
109
109
 
110
110
  new_requirement =
111
111
  if (exact_req = exact_req(string_reqs))
@@ -128,7 +128,7 @@ module Dependabot
128
128
 
129
129
  sig { params(req: Dependabot::DependencyRequirement).returns(Dependabot::DependencyRequirement) }
130
130
  def update_version_requirement_if_needed(req)
131
- string_reqs = req[:requirement].split(",").map(&:strip)
131
+ string_reqs = T.must(req.requirement_string).split(",").map(&:strip)
132
132
  ruby_reqs = string_reqs.map { |r| Dependabot::Cargo::Requirement.new(r) }
133
133
 
134
134
  return req if ruby_reqs.all? { |r| r.satisfied_by?(target_version) }
@@ -485,8 +485,8 @@ module Dependabot
485
485
  )
486
486
  next unless checker.git_dependency?
487
487
 
488
- url = T.must(dep.requirements.find { |r| r.dig(:source, :type) == "git" })
489
- .fetch(:source).fetch(:url)
488
+ requirement = T.must(dep.requirements.find { |r| r.source_string("type") == "git" })
489
+ url = T.must(requirement.source_string("url"))
490
490
 
491
491
  if checker.git_repo_reachable?
492
492
  T.must(@reachable_git_urls) << url
@@ -616,8 +616,8 @@ module Dependabot
616
616
  sig { returns(T.nilable(String)) }
617
617
  def git_source_url
618
618
  dependency.requirements
619
- .find { |r| r.dig(:source, :type) == "git" }
620
- &.dig(:source, :url)
619
+ .find { |r| r.source_string("type") == "git" }
620
+ &.source_string("url")
621
621
  end
622
622
 
623
623
  sig { returns(String) }
@@ -1,4 +1,4 @@
1
- # typed: strict
1
+ # typed: strong
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require "sorbet-runtime"
@@ -221,7 +221,8 @@ module Dependabot
221
221
  # of the latest tag that looks like a version.
222
222
  if git_commit_checker.pinned_ref_looks_like_version?
223
223
  latest_tag = git_commit_checker.local_tag_for_latest_version(update_cooldown)
224
- return latest_tag&.fetch(:commit_sha) || dependency.version
224
+ commit_sha = T.cast(latest_tag&.fetch(:commit_sha), T.nilable(String))
225
+ return commit_sha || dependency.version
225
226
  end
226
227
 
227
228
  # If the dependency is pinned to a tag that doesn't look like a
@@ -241,7 +242,7 @@ module Dependabot
241
242
  if git_commit_checker.pinned_ref_looks_like_version? &&
242
243
  latest_git_tag_is_resolvable?
243
244
  new_tag = git_commit_checker.local_tag_for_latest_version(update_cooldown)
244
- return T.must(new_tag).fetch(:commit_sha)
245
+ return T.cast(T.must(new_tag).fetch(:commit_sha), String)
245
246
  end
246
247
 
247
248
  # If the dependency is pinned then there's nothing we can do.
@@ -270,7 +271,7 @@ module Dependabot
270
271
  dependency_files: dependency_files,
271
272
  dependency: dependency,
272
273
  unlock_requirement: true,
273
- replacement_git_pin: replacement_tag.fetch(:tag)
274
+ replacement_git_pin: T.cast(replacement_tag.fetch(:tag), String)
274
275
  ).prepared_dependency_files
275
276
 
276
277
  VersionResolver.new(
@@ -353,7 +354,7 @@ module Dependabot
353
354
  latest_resolvable_version
354
355
  end
355
356
 
356
- sig { returns(T.nilable(T::Hash[T.any(String, Symbol), T.anything])) }
357
+ sig { returns(T.nilable(Dependabot::DependencyRequirement::ObjectHash)) }
357
358
  def updated_source
358
359
  # Never need to update source, unless a git_dependency
359
360
  return dependency_source_details unless git_dependency?
@@ -362,18 +363,39 @@ module Dependabot
362
363
  if git_commit_checker.pinned_ref_looks_like_version? &&
363
364
  latest_git_tag_is_resolvable?
364
365
  new_tag = T.must(git_commit_checker.local_tag_for_latest_version(update_cooldown))
365
- return T.must(dependency_source_details).merge(ref: new_tag.fetch(:tag))
366
+ return source_with_ref(T.must(dependency_source_details), T.cast(new_tag.fetch(:tag), String))
366
367
  end
367
368
 
368
369
  # Otherwise return the original source
369
370
  dependency_source_details
370
371
  end
371
372
 
372
- sig { returns(T.nilable(T::Hash[T.any(String, Symbol), T.anything])) }
373
+ sig { returns(T.nilable(Dependabot::DependencyRequirement::ObjectHash)) }
373
374
  def dependency_source_details
374
375
  dependency.source_details
375
376
  end
376
377
 
378
+ sig do
379
+ params(
380
+ source: Dependabot::DependencyRequirement::ObjectHash,
381
+ ref: String
382
+ ).returns(Dependabot::DependencyRequirement::ObjectHash)
383
+ end
384
+ def source_with_ref(source, ref)
385
+ updated_source = source.dup
386
+ key = if source.key?(:ref)
387
+ :ref
388
+ elsif source.key?("ref")
389
+ "ref"
390
+ elsif source.keys.any?(Symbol)
391
+ :ref
392
+ else
393
+ "ref"
394
+ end
395
+ updated_source[key] = ref
396
+ updated_source
397
+ end
398
+
377
399
  sig { returns(T::Boolean) }
378
400
  def git_dependency?
379
401
  git_commit_checker.git_dependency?
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dependabot-cargo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.391.0
4
+ version: 0.392.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dependabot
@@ -15,14 +15,14 @@ dependencies:
15
15
  requirements:
16
16
  - - '='
17
17
  - !ruby/object:Gem::Version
18
- version: 0.391.0
18
+ version: 0.392.0
19
19
  type: :runtime
20
20
  prerelease: false
21
21
  version_requirements: !ruby/object:Gem::Requirement
22
22
  requirements:
23
23
  - - '='
24
24
  - !ruby/object:Gem::Version
25
- version: 0.391.0
25
+ version: 0.392.0
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: debug
28
28
  requirement: !ruby/object:Gem::Requirement
@@ -266,7 +266,7 @@ licenses:
266
266
  - MIT
267
267
  metadata:
268
268
  bug_tracker_uri: https://github.com/dependabot/dependabot-core/issues
269
- changelog_uri: https://github.com/dependabot/dependabot-core/releases/tag/v0.391.0
269
+ changelog_uri: https://github.com/dependabot/dependabot-core/releases/tag/v0.392.0
270
270
  rdoc_options: []
271
271
  require_paths:
272
272
  - lib