dependabot-pre_commit 0.391.0 → 0.393.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: d9441e66480f1aea2a7e43207c74d5178202caed571c30028cbd96a0c5cbb288
4
- data.tar.gz: 67b88470726c62075fd8f0241596f10b1f739c6c2f9cf5896fdb8b2fb99abc5e
3
+ metadata.gz: 2bfe9bb22dc185a3f722c6fdcbe055916d6f397b93056d5f7bb82f38a6d1722e
4
+ data.tar.gz: 14564e38830155479234245206f051bbed756090da8eae6f20d8757d41188471
5
5
  SHA512:
6
- metadata.gz: d65531a2e9e8ed53dae84924607b6fc810cce99fde8cf8074ecae41c16e1a3f4ef12d561957deb996deba4fb96cf25953d5fe7d74930f895cdba1a2b6a877fec
7
- data.tar.gz: b1722f3541c5a4d4fed125d4a3d5018099d09d33fa39fdd73917bc7dcea60d436c9c41970ab16ddddd1657557c7ee7599b1d94b60cb89c62007b3e9d22186220
6
+ metadata.gz: 0a978739dd13991e522432c9ce44186414a713b4366dfa9f023199e3b54413ffc86e850d21c9544235435980bd0419f8aa97c7e96ed7a31a6d789318ba50028b
7
+ data.tar.gz: da754260a6103bfc2575d468c92c9313e93ddccd78215d524e85f9537461709f1186e2d0b6fa833ddaf4279edd73dc305f893c3eb28d6baf381c55d6d63f6216
@@ -2,6 +2,7 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require "sorbet-runtime"
5
+ require "dependabot/dependency_requirement"
5
6
  require "dependabot/package/release_cooldown_options"
6
7
 
7
8
  module Dependabot
@@ -41,9 +42,9 @@ module Dependabot
41
42
 
42
43
  sig do
43
44
  params(
44
- source: T::Hash[Symbol, Object],
45
+ source: Dependabot::DependencyRequirement::ObjectHash,
45
46
  credentials: T::Array[Dependabot::Credential],
46
- requirements: T::Array[T::Hash[Symbol, Object]],
47
+ requirements: T::Array[Dependabot::DependencyRequirement],
47
48
  current_version: T.nilable(String),
48
49
  cooldown_options: T.nilable(Dependabot::Package::ReleaseCooldownOptions)
49
50
  ).void
@@ -51,7 +52,10 @@ module Dependabot
51
52
  def initialize(source:, credentials:, requirements:, current_version:, cooldown_options: nil)
52
53
  @source = source
53
54
  @credentials = credentials
54
- @requirements = requirements
55
+ @requirements = T.let(
56
+ requirements.map { |requirement| Dependabot::DependencyRequirement.create(requirement) },
57
+ T::Array[Dependabot::DependencyRequirement]
58
+ )
55
59
  @current_version = current_version
56
60
  @cooldown_options = cooldown_options
57
61
  end
@@ -65,18 +69,21 @@ module Dependabot
65
69
  # Generate updated requirements for the new version
66
70
  # Should preserve the original version constraint operator (>=, ~=, etc.)
67
71
  # and update the source hash with the new original_string
68
- sig { abstract.params(latest_version: String).returns(T::Array[T::Hash[Symbol, Object]]) }
72
+ sig do
73
+ abstract.params(latest_version: String)
74
+ .returns(T::Array[Dependabot::DependencyRequirement])
75
+ end
69
76
  def updated_requirements(latest_version); end
70
77
 
71
78
  private
72
79
 
73
- sig { returns(T::Hash[Symbol, Object]) }
80
+ sig { returns(Dependabot::DependencyRequirement::ObjectHash) }
74
81
  attr_reader :source
75
82
 
76
83
  sig { returns(T::Array[Dependabot::Credential]) }
77
84
  attr_reader :credentials
78
85
 
79
- sig { returns(T::Array[T::Hash[Symbol, Object]]) }
86
+ sig { returns(T::Array[Dependabot::DependencyRequirement]) }
80
87
  attr_reader :requirements
81
88
 
82
89
  sig { returns(T.nilable(String)) }
@@ -87,13 +94,80 @@ module Dependabot
87
94
 
88
95
  sig { returns(T.nilable(String)) }
89
96
  def package_name
90
- source[:package_name]&.to_s
97
+ source_string(source, "package_name")
91
98
  end
92
99
 
93
- sig { params(requirement: T.nilable(T::Hash[Symbol, Object])).returns(T.nilable(String)) }
100
+ sig do
101
+ params(requirement: T.nilable(Dependabot::DependencyRequirement))
102
+ .returns(T.nilable(String))
103
+ end
94
104
  def requirement_string(requirement)
95
- value = requirement&.dig(:requirement)
96
- value if value.is_a?(String)
105
+ requirement&.requirement_string
106
+ end
107
+
108
+ sig do
109
+ params(
110
+ requirement: Dependabot::DependencyRequirement
111
+ ).returns(T.nilable(Dependabot::DependencyRequirement::ObjectHash))
112
+ end
113
+ def additional_dependency_source(requirement)
114
+ details = requirement.source_hash
115
+ return unless details
116
+ return unless source_string(details, "type") == "additional_dependency"
117
+
118
+ details
119
+ end
120
+
121
+ sig do
122
+ params(
123
+ requirement: Dependabot::DependencyRequirement,
124
+ new_requirement: T.nilable(String),
125
+ original_string: String
126
+ ).returns(Dependabot::DependencyRequirement)
127
+ end
128
+ def build_requirement_entry(requirement, new_requirement:, original_string:)
129
+ original_source = T.must(additional_dependency_source(requirement))
130
+ new_source = source_with_value(original_source, "original_string", original_string)
131
+
132
+ Dependabot::DependencyRequirement.create(
133
+ requirement.merge(requirement: new_requirement, source: new_source)
134
+ )
135
+ end
136
+
137
+ sig do
138
+ params(
139
+ details: Dependabot::DependencyRequirement::ObjectHash,
140
+ key: String
141
+ ).returns(T.nilable(String))
142
+ end
143
+ def source_string(details, key)
144
+ value = details.key?(key.to_sym) ? details[key.to_sym] : details[key]
145
+ return if value.nil?
146
+ return value if value.is_a?(String)
147
+
148
+ raise TypeError, "source #{key} must be a string or nil"
149
+ end
150
+
151
+ sig do
152
+ params(
153
+ details: Dependabot::DependencyRequirement::ObjectHash,
154
+ key: String,
155
+ value: Object
156
+ ).returns(Dependabot::DependencyRequirement::ObjectHash)
157
+ end
158
+ def source_with_value(details, key, value)
159
+ updated = details.dup
160
+ actual_key = if details.key?(key.to_sym)
161
+ key.to_sym
162
+ elsif details.key?(key)
163
+ key
164
+ elsif details.keys.any?(Symbol)
165
+ key.to_sym
166
+ else
167
+ key
168
+ end
169
+ updated[actual_key] = value
170
+ updated
97
171
  end
98
172
  end
99
173
  end
@@ -1,4 +1,4 @@
1
- # typed: strict
1
+ # typed: strong
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require "sorbet-runtime"
@@ -24,26 +24,28 @@ module Dependabot
24
24
  )
25
25
  end
26
26
 
27
- sig { override.params(latest_version: String).returns(T::Array[T::Hash[Symbol, Object]]) }
27
+ sig do
28
+ override.params(latest_version: String)
29
+ .returns(T::Array[Dependabot::DependencyRequirement])
30
+ end
28
31
  def updated_requirements(latest_version)
29
32
  requirements.map do |original_req|
30
- original_source = original_req[:source]
31
- next original_req unless original_source.is_a?(Hash)
32
- next original_req unless original_source[:type] == "additional_dependency"
33
+ original_source = additional_dependency_source(original_req)
34
+ next original_req unless original_source
33
35
 
34
36
  original_requirement = requirement_string(original_req)
35
37
  new_requirement = build_updated_requirement(original_requirement, latest_version)
36
38
 
37
39
  new_original_string = build_original_string(
38
- package_name: original_source[:original_name] || original_source[:package_name],
40
+ package_name: source_string(original_source, "original_name") ||
41
+ source_string(original_source, "package_name"),
39
42
  requirement: new_requirement
40
43
  )
41
44
 
42
- new_source = original_source.merge(original_string: new_original_string)
43
-
44
- original_req.merge(
45
- requirement: new_requirement,
46
- source: new_source
45
+ build_requirement_entry(
46
+ original_req,
47
+ new_requirement: new_requirement,
48
+ original_string: new_original_string
47
49
  )
48
50
  end
49
51
  end
@@ -1,4 +1,4 @@
1
- # typed: strict
1
+ # typed: strong
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require "sorbet-runtime"
@@ -24,25 +24,27 @@ module Dependabot
24
24
  )
25
25
  end
26
26
 
27
- sig { override.params(latest_version: String).returns(T::Array[T::Hash[Symbol, Object]]) }
27
+ sig do
28
+ override.params(latest_version: String)
29
+ .returns(T::Array[Dependabot::DependencyRequirement])
30
+ end
28
31
  def updated_requirements(latest_version)
29
32
  requirements.map do |original_req|
30
- original_source = original_req[:source]
31
- next original_req unless original_source.is_a?(Hash)
32
- next original_req unless original_source[:type] == "additional_dependency"
33
+ original_source = additional_dependency_source(original_req)
34
+ next original_req unless original_source
33
35
 
34
36
  new_requirement = "v#{latest_version}"
35
37
 
36
38
  new_original_string = build_original_string(
37
- original_name: original_source[:original_name] || original_source[:package_name],
39
+ original_name: source_string(original_source, "original_name") ||
40
+ source_string(original_source, "package_name"),
38
41
  requirement: new_requirement
39
42
  )
40
43
 
41
- new_source = original_source.merge(original_string: new_original_string)
42
-
43
- original_req.merge(
44
- requirement: new_requirement,
45
- source: new_source
44
+ build_requirement_entry(
45
+ original_req,
46
+ new_requirement: new_requirement,
47
+ original_string: new_original_string
46
48
  )
47
49
  end
48
50
  end
@@ -1,4 +1,4 @@
1
- # typed: strict
1
+ # typed: strong
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require "excon"
@@ -25,26 +25,28 @@ module Dependabot
25
25
  )
26
26
  end
27
27
 
28
- sig { override.params(latest_version: String).returns(T::Array[T::Hash[Symbol, Object]]) }
28
+ sig do
29
+ override.params(latest_version: String)
30
+ .returns(T::Array[Dependabot::DependencyRequirement])
31
+ end
29
32
  def updated_requirements(latest_version)
30
33
  requirements.map do |original_req|
31
- original_source = original_req[:source]
32
- next original_req unless original_source.is_a?(Hash)
33
- next original_req unless original_source[:type] == "additional_dependency"
34
+ original_source = additional_dependency_source(original_req)
35
+ next original_req unless original_source
34
36
 
35
37
  original_requirement = requirement_string(original_req)
36
38
  new_requirement = build_updated_requirement(original_requirement, latest_version)
37
39
 
38
40
  new_original_string = build_original_string(
39
- package_name: original_source[:original_name] || original_source[:package_name],
41
+ package_name: source_string(original_source, "original_name") ||
42
+ source_string(original_source, "package_name"),
40
43
  requirement: new_requirement
41
44
  )
42
45
 
43
- new_source = original_source.merge(original_string: new_original_string)
44
-
45
- original_req.merge(
46
- requirement: new_requirement,
47
- source: new_source
46
+ build_requirement_entry(
47
+ original_req,
48
+ new_requirement: new_requirement,
49
+ original_string: new_original_string
48
50
  )
49
51
  end
50
52
  end
@@ -1,4 +1,4 @@
1
- # typed: strict
1
+ # typed: strong
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require "sorbet-runtime"
@@ -26,27 +26,29 @@ module Dependabot
26
26
  )
27
27
  end
28
28
 
29
- sig { override.params(latest_version: String).returns(T::Array[T::Hash[Symbol, Object]]) }
29
+ sig do
30
+ override.params(latest_version: String)
31
+ .returns(T::Array[Dependabot::DependencyRequirement])
32
+ end
30
33
  def updated_requirements(latest_version)
31
34
  requirements.map do |original_req|
32
- original_source = original_req[:source]
33
- next original_req unless original_source.is_a?(Hash)
34
- next original_req unless original_source[:type] == "additional_dependency"
35
+ original_source = additional_dependency_source(original_req)
36
+ next original_req unless original_source
35
37
 
36
38
  original_requirement = requirement_string(original_req)
37
39
  new_requirement = build_updated_requirement(original_requirement, latest_version)
38
40
 
39
41
  new_original_string = build_original_string(
40
- original_name: original_source[:original_name] || original_source[:package_name],
41
- extras: original_source[:extras],
42
+ original_name: source_string(original_source, "original_name") ||
43
+ source_string(original_source, "package_name"),
44
+ extras: source_string(original_source, "extras"),
42
45
  requirement: new_requirement
43
46
  )
44
47
 
45
- new_source = original_source.merge(original_string: new_original_string)
46
-
47
- original_req.merge(
48
- requirement: new_requirement,
49
- source: new_source
48
+ build_requirement_entry(
49
+ original_req,
50
+ new_requirement: new_requirement,
51
+ original_string: new_original_string
50
52
  )
51
53
  end
52
54
  end
@@ -180,14 +182,15 @@ module Dependabot
180
182
  )
181
183
 
182
184
  updated_reqs = updater.updated_requirements
183
- updated_req = updated_reqs.first&.fetch(:requirement, nil)
185
+ updated_req = updated_reqs.first&.requirement
184
186
 
185
187
  return ">=#{new_version}" if updated_req == :unfixable
186
188
 
187
- if updated_req == original_requirement
189
+ updated_req_string = T.cast(updated_req, T.nilable(String))
190
+ if updated_req_string == original_requirement
188
191
  force_bump_lower_bounds(original_requirement, new_version)
189
192
  else
190
- updated_req || ">=#{new_version}"
193
+ updated_req_string || ">=#{new_version}"
191
194
  end
192
195
  end
193
196
 
@@ -1,4 +1,4 @@
1
- # typed: strict
1
+ # typed: strong
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require "excon"
@@ -25,26 +25,28 @@ module Dependabot
25
25
  )
26
26
  end
27
27
 
28
- sig { override.params(latest_version: String).returns(T::Array[T::Hash[Symbol, Object]]) }
28
+ sig do
29
+ override.params(latest_version: String)
30
+ .returns(T::Array[Dependabot::DependencyRequirement])
31
+ end
29
32
  def updated_requirements(latest_version)
30
33
  requirements.map do |original_req|
31
- original_source = original_req[:source]
32
- next original_req unless original_source.is_a?(Hash)
33
- next original_req unless original_source[:type] == "additional_dependency"
34
+ original_source = additional_dependency_source(original_req)
35
+ next original_req unless original_source
34
36
 
35
37
  original_requirement = requirement_string(original_req)
36
38
  new_requirement = build_updated_requirement(original_requirement, latest_version)
37
39
 
38
40
  new_original_string = build_original_string(
39
- package_name: original_source[:original_name] || original_source[:package_name],
41
+ package_name: source_string(original_source, "original_name") ||
42
+ source_string(original_source, "package_name"),
40
43
  requirement: new_requirement
41
44
  )
42
45
 
43
- new_source = original_source.merge(original_string: new_original_string)
44
-
45
- original_req.merge(
46
- requirement: new_requirement,
47
- source: new_source
46
+ build_requirement_entry(
47
+ original_req,
48
+ new_requirement: new_requirement,
49
+ original_string: new_original_string
48
50
  )
49
51
  end
50
52
  end
@@ -1,4 +1,4 @@
1
- # typed: strict
1
+ # typed: strong
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require "excon"
@@ -25,27 +25,29 @@ module Dependabot
25
25
  )
26
26
  end
27
27
 
28
- sig { override.params(latest_version: String).returns(T::Array[T::Hash[Symbol, Object]]) }
28
+ sig do
29
+ override.params(latest_version: String)
30
+ .returns(T::Array[Dependabot::DependencyRequirement])
31
+ end
29
32
  def updated_requirements(latest_version)
30
33
  requirements.map do |original_req|
31
- original_source = original_req[:source]
32
- next original_req unless original_source.is_a?(Hash)
33
- next original_req unless original_source[:type] == "additional_dependency"
34
+ original_source = additional_dependency_source(original_req)
35
+ next original_req unless original_source
34
36
 
35
37
  original_requirement = requirement_string(original_req)
36
38
  new_requirement = build_updated_requirement(original_requirement, latest_version)
37
39
 
38
40
  new_original_string = build_original_string(
39
- package_name: original_source[:original_name] || original_source[:package_name],
41
+ package_name: source_string(original_source, "original_name") ||
42
+ source_string(original_source, "package_name"),
40
43
  requirement: new_requirement,
41
- cli: original_source[:extras] == "cli"
44
+ cli: source_string(original_source, "extras") == "cli"
42
45
  )
43
46
 
44
- new_source = original_source.merge(original_string: new_original_string)
45
-
46
- original_req.merge(
47
- requirement: new_requirement,
48
- source: new_source
47
+ build_requirement_entry(
48
+ original_req,
49
+ new_requirement: new_requirement,
50
+ original_string: new_original_string
49
51
  )
50
52
  end
51
53
  end
@@ -99,15 +99,14 @@ module Dependabot
99
99
  ).returns(T.nilable(T::Array[T::Hash[String, Object]]))
100
100
  end
101
101
  def fetch_from_github(source, revision)
102
- response = github_client.send(
103
- :contents,
102
+ response = github_client.contents(
104
103
  source.repo,
105
104
  path: HOOKS_FILE,
106
105
  ref: revision
107
106
  )
108
- return nil unless response
109
107
 
110
- content = Base64.decode64(response.content)
108
+ resource = T.cast(response, Sawyer::Resource)
109
+ content = Base64.decode64(T.cast(resource[:content], String))
111
110
  parse_hooks_yaml(content)
112
111
  rescue Octokit::NotFound
113
112
  Dependabot.logger.debug("#{HOOKS_FILE} not found in #{source.repo}@#{revision}")
@@ -60,19 +60,21 @@ module Dependabot
60
60
 
61
61
  sig do
62
62
  params(file: Dependabot::DependencyFile)
63
- .returns(T::Array[[T::Hash[Symbol, Object], T::Hash[Symbol, Object]]])
63
+ .returns(
64
+ T::Array[
65
+ [Dependabot::DependencyRequirement, Dependabot::DependencyRequirement]
66
+ ]
67
+ )
64
68
  end
65
69
  def requirement_pairs_for_file(file)
66
70
  pairs = dependency.requirements.zip(T.must(dependency.previous_requirements))
67
71
  filtered_pairs = pairs.reject do |new_req, old_req|
68
72
  next true unless old_req
69
73
 
70
- file_name = T.cast(new_req[:file], T.nilable(String))
74
+ file_name = new_req.file
71
75
  next true if file_name != file.name
72
76
 
73
- new_source = T.cast(new_req[:source], T.nilable(T::Hash[Symbol, Object]))
74
- old_source = T.cast(old_req[:source], T.nilable(T::Hash[Symbol, Object]))
75
- new_source == old_source
77
+ new_req.source == old_req.source
76
78
  end
77
79
 
78
80
  filtered_pairs.map { |new_req, old_req| [new_req, T.must(old_req)] }
@@ -81,15 +83,12 @@ module Dependabot
81
83
  sig do
82
84
  params(
83
85
  content: String,
84
- new_req: T::Hash[Symbol, Object],
85
- old_req: T::Hash[Symbol, Object]
86
+ new_req: Dependabot::DependencyRequirement,
87
+ old_req: Dependabot::DependencyRequirement
86
88
  ).returns(String)
87
89
  end
88
90
  def apply_requirement_update(content, new_req, old_req)
89
- new_source = T.cast(new_req.fetch(:source), T::Hash[Symbol, Object])
90
- source_type = T.cast(new_source.fetch(:type), String)
91
-
92
- case source_type
91
+ case new_req.source_string("type")
93
92
  when "git"
94
93
  apply_git_requirement_update(content, new_req, old_req)
95
94
  when "additional_dependency"
@@ -102,20 +101,16 @@ module Dependabot
102
101
  sig do
103
102
  params(
104
103
  content: String,
105
- new_req: T::Hash[Symbol, Object],
106
- old_req: T::Hash[Symbol, Object]
104
+ new_req: Dependabot::DependencyRequirement,
105
+ old_req: Dependabot::DependencyRequirement
107
106
  ).returns(String)
108
107
  end
109
108
  def apply_git_requirement_update(content, new_req, old_req)
110
- new_source = T.cast(new_req.fetch(:source), T::Hash[Symbol, Object])
111
- old_source = T.cast(old_req.fetch(:source), T::Hash[Symbol, Object])
112
- repo_url = T.cast(old_source.fetch(:url), String)
113
- old_ref = T.cast(old_source.fetch(:ref), String)
114
- new_ref = T.cast(new_source.fetch(:ref), String)
115
-
116
- new_metadata = T.cast(new_req.fetch(:metadata, {}), T::Hash[Symbol, Object])
117
- old_version = T.cast(new_metadata[:comment_version], T.nilable(String))
118
- new_version = T.cast(new_metadata[:new_comment_version], T.nilable(String))
109
+ repo_url = T.must(old_req.source_string("url"))
110
+ old_ref = T.must(old_req.source_string("ref"))
111
+ new_ref = T.must(new_req.source_string("ref"))
112
+ old_version = new_req.metadata_string("comment_version")
113
+ new_version = new_req.metadata_string("new_comment_version")
119
114
 
120
115
  replace_ref_in_content(
121
116
  content,
@@ -130,16 +125,13 @@ module Dependabot
130
125
  sig do
131
126
  params(
132
127
  content: String,
133
- new_req: T::Hash[Symbol, Object],
134
- old_req: T::Hash[Symbol, Object]
128
+ new_req: Dependabot::DependencyRequirement,
129
+ old_req: Dependabot::DependencyRequirement
135
130
  ).returns(String)
136
131
  end
137
132
  def apply_additional_dependency_update(content, new_req, old_req)
138
- old_source = T.cast(old_req.fetch(:source), T::Hash[Symbol, Object])
139
- new_source = T.cast(new_req.fetch(:source), T::Hash[Symbol, Object])
140
-
141
- old_string = T.cast(old_source.fetch(:original_string), String)
142
- new_string = T.cast(new_source.fetch(:original_string), String)
133
+ old_string = T.must(old_req.source_string("original_string"))
134
+ new_string = T.must(new_req.source_string("original_string"))
143
135
 
144
136
  replace_additional_dependency_in_content(content, old_string, new_string)
145
137
  end
@@ -60,11 +60,19 @@ module Dependabot
60
60
  )
61
61
  end
62
62
 
63
- sig { params(source: T.nilable(T::Hash[Symbol, Object])).returns(Dependabot::GitCommitChecker) }
63
+ sig do
64
+ params(source: T.nilable(Dependabot::DependencyRequirement::ObjectHash))
65
+ .returns(Dependabot::GitCommitChecker)
66
+ end
64
67
  def git_commit_checker_for(source)
65
68
  @git_commit_checkers ||= T.let(
66
69
  {},
67
- T.nilable(T::Hash[T.nilable(T::Hash[Symbol, Object]), Dependabot::GitCommitChecker])
70
+ T.nilable(
71
+ T::Hash[
72
+ T.nilable(Dependabot::DependencyRequirement::ObjectHash),
73
+ Dependabot::GitCommitChecker
74
+ ]
75
+ )
68
76
  )
69
77
 
70
78
  @git_commit_checkers[source] ||= Dependabot::GitCommitChecker.new(
@@ -73,9 +81,17 @@ module Dependabot
73
81
  ignored_versions: ignored_versions,
74
82
  raise_on_ignored: raise_on_ignored,
75
83
  consider_version_branches_pinned: @consider_version_branches_pinned,
76
- dependency_source_details: source || @dependency_source_details
84
+ dependency_source_details: source ? symbolize_source(source) : @dependency_source_details
77
85
  )
78
86
  end
87
+
88
+ sig do
89
+ params(source: Dependabot::DependencyRequirement::ObjectHash)
90
+ .returns(T::Hash[Symbol, Object])
91
+ end
92
+ def symbolize_source(source)
93
+ source.to_h { |key, value| [key.to_sym, value] }
94
+ end
79
95
  end
80
96
  end
81
97
  end
@@ -1,4 +1,4 @@
1
- # typed: strict
1
+ # typed: strong
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require "sorbet-runtime"
@@ -14,14 +14,10 @@ module Dependabot
14
14
 
15
15
  sig { override.returns(T.nilable(Dependabot::Source)) }
16
16
  def look_up_source
17
- info = dependency.requirements.filter_map { |r| r[:source] }.first
18
-
19
- url =
20
- if info.nil?
21
- dependency.name
22
- else
23
- info[:url] || info[:repo_url] || info["url"] || dependency.name
24
- end
17
+ requirement = dependency.requirements.find(&:source_hash)
18
+ url = requirement&.source_string("url") ||
19
+ requirement&.source_string("repo_url") ||
20
+ dependency.name
25
21
  Source.from_url(url)
26
22
  end
27
23
  end
@@ -1,4 +1,4 @@
1
- # typed: strict
1
+ # typed: strong
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require "sorbet-runtime"
@@ -62,7 +62,7 @@ module Dependabot
62
62
  def version_tag_release
63
63
  return unless git_commit_checker.pinned_ref_looks_like_version? && latest_version_tag
64
64
 
65
- latest_version = pre_commit_version(latest_version_tag&.fetch(:version))
65
+ latest_version = pre_commit_version(tag_version(T.must(latest_version_tag)))
66
66
  return unless latest_version
67
67
 
68
68
  return current_version if shortened_semver_eq?(dependency.version, latest_version.to_s)
@@ -76,7 +76,7 @@ module Dependabot
76
76
 
77
77
  if latest_version_tag
78
78
  if git_commit_checker.local_tag_for_pinned_sha || version_comment?
79
- return pre_commit_version(T.must(latest_version_tag).fetch(:version))
79
+ return pre_commit_version(tag_version(T.must(latest_version_tag)))
80
80
  end
81
81
 
82
82
  return latest_commit_for_pinned_ref
@@ -94,7 +94,7 @@ module Dependabot
94
94
  end
95
95
 
96
96
  ref = git_commit_checker.local_ref_for_latest_version_matching_existing_precision
97
- return ref if ref && current_version && ref.fetch(:version) > current_version
97
+ return ref if ref && current_version && tag_version(ref) && T.must(tag_version(ref)) > current_version
98
98
 
99
99
  git_commit_checker.local_ref_for_latest_version_lower_precision
100
100
  end,
@@ -126,6 +126,14 @@ module Dependabot
126
126
  git_commit_checker.max_local_tag(matching)
127
127
  end
128
128
 
129
+ sig { params(tag: T::Hash[Symbol, Object]).returns(T.nilable(Gem::Version)) }
130
+ def tag_version(tag)
131
+ return tag.version if tag.is_a?(Dependabot::GitTagDetails)
132
+
133
+ version = tag[:version]
134
+ version if version.is_a?(Gem::Version)
135
+ end
136
+
129
137
  sig do
130
138
  params(
131
139
  prefix: String,
@@ -159,7 +167,7 @@ module Dependabot
159
167
 
160
168
  sig { returns(T.nilable(String)) }
161
169
  def frozen_comment_ref
162
- comment = dependency.requirements.first&.dig(:metadata, :comment)
170
+ comment = dependency.requirements.first&.metadata_string("comment")
163
171
  return nil unless comment
164
172
 
165
173
  match = comment.match(CommentVersionHelper::FROZEN_COMMENT_REF_PATTERN)
@@ -173,7 +181,7 @@ module Dependabot
173
181
 
174
182
  sig { returns(T::Boolean) }
175
183
  def version_comment?
176
- comment = dependency.requirements.first&.dig(:metadata, :comment)
184
+ comment = dependency.requirements.first&.metadata_string("comment")
177
185
  return false unless comment
178
186
 
179
187
  comment.match?(CommentVersionHelper::COMMENT_VERSION_PATTERN)
@@ -1,4 +1,4 @@
1
- # typed: strict
1
+ # typed: strong
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require "sorbet-runtime"
@@ -384,13 +384,13 @@ module Dependabot
384
384
  # when the dependency's stored version is a commit SHA.
385
385
  sig { returns(T.nilable(Dependabot::Version)) }
386
386
  def version_from_frozen_comment
387
- comment = dependency.requirements.first&.dig(:metadata, :comment)
387
+ comment = dependency.requirements.first&.metadata_string("comment")
388
388
  return nil unless comment
389
389
 
390
390
  match = comment.match(CommentVersionHelper::FROZEN_COMMENT_REF_PATTERN)
391
391
  return nil unless match
392
392
 
393
- version_str = match[1].sub(/\Av/i, "")
393
+ version_str = T.must(match[1]).sub(/\Av/i, "")
394
394
  return nil unless Dependabot::PreCommit::Version.correct?(version_str)
395
395
 
396
396
  Dependabot::PreCommit::Version.new(version_str)
@@ -50,23 +50,17 @@ module Dependabot
50
50
  return wrap_requirements(additional_dependency_updated_requirements) if additional_dependency?
51
51
 
52
52
  updated_reqs = dependency.requirements.map do |req|
53
- source = T.cast(req[:source], T.nilable(T::Hash[Symbol, Object]))
53
+ source = req.source_hash
54
+ next req unless source
55
+
54
56
  updated = updated_ref(source)
55
57
  next req unless updated
56
58
 
57
- current = T.cast(source&.[](:ref), T.nilable(String))
58
-
59
- # Maintain short git hash when the updated SHA starts with the current SHA
60
- if T.cast(req[:type], T.nilable(String)) == "git" &&
61
- git_commit_checker.ref_looks_like_commit_sha?(updated) &&
62
- current && git_commit_checker.ref_looks_like_commit_sha?(current) &&
63
- updated.start_with?(current)
64
- next req
65
- end
66
-
67
- new_source = T.must(source).merge(ref: updated)
59
+ new_source = hash_with_value(source, "ref", updated)
68
60
  new_metadata = updated_comment_version_metadata(req, updated)
69
- req.merge(source: new_source, metadata: new_metadata)
61
+ Dependabot::DependencyRequirement.create(
62
+ req.merge(source: new_source, metadata: new_metadata)
63
+ )
70
64
  end
71
65
  wrap_requirements(updated_reqs)
72
66
  end
@@ -166,7 +160,10 @@ module Dependabot
166
160
  )
167
161
  end
168
162
 
169
- sig { params(source: T.nilable(T::Hash[Symbol, Object])).returns(T.nilable(String)) }
163
+ sig do
164
+ params(source: T.nilable(Dependabot::DependencyRequirement::ObjectHash))
165
+ .returns(T.nilable(String))
166
+ end
170
167
  def updated_ref(source)
171
168
  return unless git_commit_checker.git_dependency?
172
169
 
@@ -175,7 +172,7 @@ module Dependabot
175
172
  # Return the git tag if updating a pinned version
176
173
  if source_git_commit_checker.pinned_ref_looks_like_version? &&
177
174
  (new_tag = T.must(latest_version_finder).latest_version_tag)
178
- return T.cast(new_tag.fetch(:tag), String)
175
+ return tag_name(new_tag)
179
176
  end
180
177
 
181
178
  # Return the pinned git commit if one is available
@@ -192,9 +189,7 @@ module Dependabot
192
189
  new_tag = T.must(latest_version_finder).latest_version_tag
193
190
 
194
191
  if new_tag
195
- if version_from_comment || git_commit_checker.local_tag_for_pinned_sha
196
- return T.cast(new_tag.fetch(:commit_sha), String)
197
- end
192
+ return tag_commit_sha(new_tag) if version_from_comment || git_commit_checker.local_tag_for_pinned_sha
198
193
 
199
194
  return latest_commit_for_pinned_ref
200
195
  end
@@ -206,6 +201,20 @@ module Dependabot
206
201
  nil
207
202
  end
208
203
 
204
+ sig { params(tag: T::Hash[Symbol, Object]).returns(String) }
205
+ def tag_name(tag)
206
+ return tag.tag if tag.is_a?(Dependabot::GitTagDetails)
207
+
208
+ T.cast(tag.fetch(:tag), String)
209
+ end
210
+
211
+ sig { params(tag: T::Hash[Symbol, Object]).returns(String) }
212
+ def tag_commit_sha(tag)
213
+ return T.must(tag.commit_sha) if tag.is_a?(Dependabot::GitTagDetails)
214
+
215
+ T.cast(tag.fetch(:commit_sha), String)
216
+ end
217
+
209
218
  sig { returns(Dependabot::GitCommitChecker) }
210
219
  def git_commit_checker
211
220
  @git_commit_checker ||= T.let(git_helper.git_commit_checker, T.nilable(Dependabot::GitCommitChecker))
@@ -213,13 +222,13 @@ module Dependabot
213
222
 
214
223
  sig do
215
224
  params(
216
- req: T::Hash[Symbol, Object],
225
+ req: Dependabot::DependencyRequirement,
217
226
  new_ref: String
218
- ).returns(T::Hash[Symbol, Object])
227
+ ).returns(Dependabot::DependencyRequirement::ObjectHash)
219
228
  end
220
229
  def updated_comment_version_metadata(req, new_ref)
221
- existing_metadata = T.cast(req.fetch(:metadata, {}), T::Hash[Symbol, Object])
222
- comment = T.cast(existing_metadata[:comment], T.nilable(String))
230
+ existing_metadata = req.metadata || {}
231
+ comment = req.metadata_string("comment")
223
232
  return existing_metadata unless comment
224
233
 
225
234
  old_version = extract_version_from_comment(comment)
@@ -228,7 +237,8 @@ module Dependabot
228
237
  new_version = resolve_new_comment_version(new_ref)
229
238
  return existing_metadata unless new_version
230
239
 
231
- existing_metadata.merge(comment_version: old_version, new_comment_version: new_version)
240
+ updated = hash_with_value(existing_metadata, "comment_version", old_version)
241
+ hash_with_value(updated, "new_comment_version", new_version)
232
242
  end
233
243
 
234
244
  sig { params(comment: String).returns(T.nilable(String)) }
@@ -243,10 +253,7 @@ module Dependabot
243
253
  begin
244
254
  comment = T.let(
245
255
  @dependency.requirements
246
- .filter_map do |req|
247
- val = T.cast(req.fetch(:metadata, {}), T::Hash[Symbol, Object])[:comment]
248
- T.cast(val, T.nilable(String))
249
- end
256
+ .filter_map { |req| req.metadata_string("comment") }
250
257
  .first,
251
258
  T.nilable(String)
252
259
  )
@@ -310,16 +317,14 @@ module Dependabot
310
317
  requirement = dependency.requirements.first
311
318
  return false unless requirement
312
319
 
313
- source = T.cast(requirement[:source], T.nilable(T::Hash[Symbol, Object]))
314
- return false unless source
315
-
316
- T.cast(source[:type], T.nilable(String)) == "additional_dependency"
320
+ requirement.source_string("type") == "additional_dependency"
317
321
  end
318
322
 
319
323
  sig { returns(T.nilable(T.any(String, Gem::Version))) }
320
324
  def additional_dependency_latest_version
321
- source = T.cast(dependency.requirements.first&.dig(:source), T::Hash[Symbol, Object])
322
- language = T.cast(source[:language], T.nilable(String))
325
+ requirement = T.must(dependency.requirements.first)
326
+ source = T.must(requirement.source_hash)
327
+ language = requirement.source_string("language")
323
328
  return nil unless language && AdditionalDependencyCheckers.supported?(language)
324
329
 
325
330
  checker = additional_dependency_checker(language, source)
@@ -331,10 +336,11 @@ module Dependabot
331
336
  latest
332
337
  end
333
338
 
334
- sig { returns(T::Array[T::Hash[Symbol, Object]]) }
339
+ sig { returns(T::Array[Dependabot::DependencyRequirement]) }
335
340
  def additional_dependency_updated_requirements
336
- source = T.cast(dependency.requirements.first&.dig(:source), T::Hash[Symbol, Object])
337
- language = T.cast(source[:language], T.nilable(String))
341
+ requirement = T.must(dependency.requirements.first)
342
+ source = T.must(requirement.source_hash)
343
+ language = requirement.source_string("language")
338
344
  return dependency.requirements unless language && AdditionalDependencyCheckers.supported?(language)
339
345
 
340
346
  checker = additional_dependency_checker(language, source)
@@ -349,7 +355,7 @@ module Dependabot
349
355
  sig do
350
356
  params(
351
357
  language: String,
352
- source: T::Hash[Symbol, Object]
358
+ source: Dependabot::DependencyRequirement::ObjectHash
353
359
  ).returns(T.nilable(Dependabot::PreCommit::AdditionalDependencyCheckers::Base))
354
360
  end
355
361
  def additional_dependency_checker(language, source)
@@ -365,6 +371,28 @@ module Dependabot
365
371
  Dependabot.logger.error("Error creating checker for #{language}: #{e.message}")
366
372
  nil
367
373
  end
374
+
375
+ sig do
376
+ params(
377
+ hash: Dependabot::DependencyRequirement::ObjectHash,
378
+ key: String,
379
+ value: Object
380
+ ).returns(Dependabot::DependencyRequirement::ObjectHash)
381
+ end
382
+ def hash_with_value(hash, key, value)
383
+ updated = hash.dup
384
+ actual_key = if hash.key?(key.to_sym)
385
+ key.to_sym
386
+ elsif hash.key?(key)
387
+ key
388
+ elsif hash.keys.any?(Symbol)
389
+ key.to_sym
390
+ else
391
+ key
392
+ end
393
+ updated[actual_key] = value
394
+ updated
395
+ end
368
396
  end
369
397
  end
370
398
  end
@@ -29,7 +29,7 @@ Dependabot::Dependency.register_humanized_previous_version_builder(
29
29
  return nil unless previous_reqs
30
30
 
31
31
  comment = previous_reqs
32
- .filter_map { |r| r.dig(:metadata, :comment) }
32
+ .filter_map { |requirement| requirement.metadata_string("comment") }
33
33
  .first
34
34
  return nil unless comment
35
35
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dependabot-pre_commit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.391.0
4
+ version: 0.393.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dependabot
@@ -15,84 +15,84 @@ dependencies:
15
15
  requirements:
16
16
  - - '='
17
17
  - !ruby/object:Gem::Version
18
- version: 0.391.0
18
+ version: 0.393.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.393.0
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: dependabot-cargo
28
28
  requirement: !ruby/object:Gem::Requirement
29
29
  requirements:
30
30
  - - '='
31
31
  - !ruby/object:Gem::Version
32
- version: 0.391.0
32
+ version: 0.393.0
33
33
  type: :runtime
34
34
  prerelease: false
35
35
  version_requirements: !ruby/object:Gem::Requirement
36
36
  requirements:
37
37
  - - '='
38
38
  - !ruby/object:Gem::Version
39
- version: 0.391.0
39
+ version: 0.393.0
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: dependabot-common
42
42
  requirement: !ruby/object:Gem::Requirement
43
43
  requirements:
44
44
  - - '='
45
45
  - !ruby/object:Gem::Version
46
- version: 0.391.0
46
+ version: 0.393.0
47
47
  type: :runtime
48
48
  prerelease: false
49
49
  version_requirements: !ruby/object:Gem::Requirement
50
50
  requirements:
51
51
  - - '='
52
52
  - !ruby/object:Gem::Version
53
- version: 0.391.0
53
+ version: 0.393.0
54
54
  - !ruby/object:Gem::Dependency
55
55
  name: dependabot-go_modules
56
56
  requirement: !ruby/object:Gem::Requirement
57
57
  requirements:
58
58
  - - '='
59
59
  - !ruby/object:Gem::Version
60
- version: 0.391.0
60
+ version: 0.393.0
61
61
  type: :runtime
62
62
  prerelease: false
63
63
  version_requirements: !ruby/object:Gem::Requirement
64
64
  requirements:
65
65
  - - '='
66
66
  - !ruby/object:Gem::Version
67
- version: 0.391.0
67
+ version: 0.393.0
68
68
  - !ruby/object:Gem::Dependency
69
69
  name: dependabot-npm_and_yarn
70
70
  requirement: !ruby/object:Gem::Requirement
71
71
  requirements:
72
72
  - - '='
73
73
  - !ruby/object:Gem::Version
74
- version: 0.391.0
74
+ version: 0.393.0
75
75
  type: :runtime
76
76
  prerelease: false
77
77
  version_requirements: !ruby/object:Gem::Requirement
78
78
  requirements:
79
79
  - - '='
80
80
  - !ruby/object:Gem::Version
81
- version: 0.391.0
81
+ version: 0.393.0
82
82
  - !ruby/object:Gem::Dependency
83
83
  name: dependabot-python
84
84
  requirement: !ruby/object:Gem::Requirement
85
85
  requirements:
86
86
  - - '='
87
87
  - !ruby/object:Gem::Version
88
- version: 0.391.0
88
+ version: 0.393.0
89
89
  type: :runtime
90
90
  prerelease: false
91
91
  version_requirements: !ruby/object:Gem::Requirement
92
92
  requirements:
93
93
  - - '='
94
94
  - !ruby/object:Gem::Version
95
- version: 0.391.0
95
+ version: 0.393.0
96
96
  - !ruby/object:Gem::Dependency
97
97
  name: debug
98
98
  requirement: !ruby/object:Gem::Requirement
@@ -338,7 +338,7 @@ licenses:
338
338
  - MIT
339
339
  metadata:
340
340
  bug_tracker_uri: https://github.com/dependabot/dependabot-core/issues
341
- changelog_uri: https://github.com/dependabot/dependabot-core/releases/tag/v0.391.0
341
+ changelog_uri: https://github.com/dependabot/dependabot-core/releases/tag/v0.393.0
342
342
  rdoc_options: []
343
343
  require_paths:
344
344
  - lib