dependabot-common 0.404.0 → 0.406.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 +4 -4
- data/lib/dependabot/clients/azure.rb +20 -2
- data/lib/dependabot/clients/bitbucket.rb +11 -12
- data/lib/dependabot/clients/comparison_commit.rb +21 -0
- data/lib/dependabot/clients/json_response_parser.rb +0 -8
- data/lib/dependabot/command_helpers.rb +3 -3
- data/lib/dependabot/error_report_context.rb +235 -0
- data/lib/dependabot/errors.rb +1 -0
- data/lib/dependabot/file_parsers/hcl2_json_document.rb +207 -0
- data/lib/dependabot/file_parsers/hcl_module_source.rb +185 -0
- data/lib/dependabot/file_updaters/base.rb +16 -0
- data/lib/dependabot/git_metadata_fetcher.rb +3 -2
- data/lib/dependabot/git_tag_details.rb +23 -59
- data/lib/dependabot/metadata_finders/base/commit_response_parser.rb +0 -8
- data/lib/dependabot/metadata_finders/base/commits_finder.rb +2 -17
- data/lib/dependabot/package/npm_package_json.rb +6 -0
- data/lib/dependabot/package/npm_package_manager_config.rb +6 -0
- data/lib/dependabot/registry_client.rb +13 -4
- data/lib/dependabot/shared_helpers.rb +1 -2
- data/lib/dependabot.rb +1 -1
- metadata +6 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 424b2083a55394433c470067d24924a788cb775aac25c49c94feb872f6488d46
|
|
4
|
+
data.tar.gz: 5146fb6e1f481c80a088d0a7d8971eb37598f901160b4d76f34b7597e275805c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: fd04daebff6d5817bef3dfd8d11083a0eaf7bc0779a87d10eaa344523cbdd2a0cb5e628581f7b1bcc73f7c5dceda280c83a18aaccb45b3c161b8a63d7c7afd96
|
|
7
|
+
data.tar.gz: e2d3160cff4c120bbbcc1420a80a13be66e15e4c20ec64092f89ed8db389a4093f649d9d03574326ec3e0e6d4535b54857caff2e955c5d4f051d02b54215959c
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
require "dependabot/shared_helpers"
|
|
5
5
|
require "dependabot/clients/json_response_parser"
|
|
6
|
+
require "dependabot/clients/comparison_commit"
|
|
6
7
|
require "excon"
|
|
7
8
|
require "sorbet-runtime"
|
|
8
9
|
|
|
@@ -372,7 +373,7 @@ module Dependabot
|
|
|
372
373
|
new_tag: T.nilable(String),
|
|
373
374
|
type: String
|
|
374
375
|
)
|
|
375
|
-
.returns(
|
|
376
|
+
.returns(T::Array[ComparisonCommit])
|
|
376
377
|
end
|
|
377
378
|
def compare(previous_tag, new_tag, type)
|
|
378
379
|
response = get(
|
|
@@ -386,7 +387,13 @@ module Dependabot
|
|
|
386
387
|
)
|
|
387
388
|
|
|
388
389
|
root = parse_json_object(response.body, "commit comparison")
|
|
389
|
-
object_array_field(root, "value", "commit comparison")
|
|
390
|
+
object_array_field(root, "value", "commit comparison").map do |commit|
|
|
391
|
+
ComparisonCommit.new(
|
|
392
|
+
sha: comparison_string(commit, "commitId"),
|
|
393
|
+
message: comparison_string(commit, "comment"),
|
|
394
|
+
html_url: comparison_string(commit, "remoteUrl")
|
|
395
|
+
)
|
|
396
|
+
end
|
|
390
397
|
end
|
|
391
398
|
|
|
392
399
|
sig { params(url: String).returns(Excon::Response) }
|
|
@@ -487,6 +494,17 @@ module Dependabot
|
|
|
487
494
|
|
|
488
495
|
private
|
|
489
496
|
|
|
497
|
+
sig { params(commit: JsonObject, key: String).returns(String) }
|
|
498
|
+
def comparison_string(commit, key)
|
|
499
|
+
value = commit[key]
|
|
500
|
+
return value if value.is_a?(String)
|
|
501
|
+
|
|
502
|
+
raise Dependabot::PrivateSourceBadResponse.new(
|
|
503
|
+
source.url,
|
|
504
|
+
"Malformed Azure commit response: commit #{key} must be a string"
|
|
505
|
+
)
|
|
506
|
+
end
|
|
507
|
+
|
|
490
508
|
sig { returns([String, String]) }
|
|
491
509
|
def response_identity
|
|
492
510
|
["Azure", source.url]
|
|
@@ -5,6 +5,7 @@ require "excon"
|
|
|
5
5
|
require "sorbet-runtime"
|
|
6
6
|
|
|
7
7
|
require "dependabot/clients/json_response_parser"
|
|
8
|
+
require "dependabot/clients/comparison_commit"
|
|
8
9
|
require "dependabot/shared_helpers"
|
|
9
10
|
|
|
10
11
|
module Dependabot
|
|
@@ -309,24 +310,22 @@ module Dependabot
|
|
|
309
310
|
object_array_field(root, "values", "tags")
|
|
310
311
|
end
|
|
311
312
|
|
|
312
|
-
sig
|
|
313
|
-
params(
|
|
314
|
-
repo: String,
|
|
315
|
-
previous_tag: String,
|
|
316
|
-
new_tag: String
|
|
317
|
-
)
|
|
318
|
-
.returns(JsonObjects)
|
|
319
|
-
end
|
|
313
|
+
sig { params(repo: String, previous_tag: String, new_tag: String).returns(T::Array[ComparisonCommit]) }
|
|
320
314
|
def compare(repo, previous_tag, new_tag)
|
|
321
315
|
path = "#{repo}/commits/?include=#{new_tag}&exclude=#{previous_tag}"
|
|
322
316
|
response = get(base_url + path)
|
|
323
317
|
|
|
324
318
|
root = parse_json_object(response.body, "commit comparison")
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
319
|
+
object_array_field(root, "values", "commit comparison").map do |commit|
|
|
320
|
+
summary = object_field(commit, "summary", "commit comparison")
|
|
321
|
+
links = object_field(commit, "links", "commit comparison")
|
|
322
|
+
html = object_field(links, "html", "commit comparison")
|
|
323
|
+
ComparisonCommit.new(
|
|
324
|
+
sha: string_field(commit, "hash", "commit comparison"),
|
|
325
|
+
message: string_field(summary, "raw", "commit comparison"),
|
|
326
|
+
html_url: string_field(html, "href", "commit comparison")
|
|
327
|
+
)
|
|
328
328
|
end
|
|
329
|
-
commits
|
|
330
329
|
end
|
|
331
330
|
|
|
332
331
|
sig { params(url: String).returns(Excon::Response) }
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# typed: strong
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require "sorbet-runtime"
|
|
5
|
+
|
|
6
|
+
module Dependabot
|
|
7
|
+
module Clients
|
|
8
|
+
class ComparisonCommit < T::ImmutableStruct
|
|
9
|
+
extend T::Sig
|
|
10
|
+
|
|
11
|
+
const :sha, String
|
|
12
|
+
const :message, String
|
|
13
|
+
const :html_url, String
|
|
14
|
+
|
|
15
|
+
sig { returns(T::Hash[Symbol, String]) }
|
|
16
|
+
def to_h
|
|
17
|
+
{ message: message, sha: sha, html_url: html_url }
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -77,14 +77,6 @@ module Dependabot
|
|
|
77
77
|
raise_bad_response(context, "#{key} must contain at least one object")
|
|
78
78
|
end
|
|
79
79
|
|
|
80
|
-
sig { params(object: JsonObject, context: String, paths: T::Array[T::Array[String]]).void }
|
|
81
|
-
def validate_string_paths(object, context, paths)
|
|
82
|
-
paths.each do |path|
|
|
83
|
-
current = T.must(path[0...-1]).reduce(object) { |value, key| object_field(value, key, context) }
|
|
84
|
-
string_field(current, T.must(path.last), context)
|
|
85
|
-
end
|
|
86
|
-
end
|
|
87
|
-
|
|
88
80
|
sig { params(context: String, message: String).returns(T.noreturn) }
|
|
89
81
|
def raise_bad_response(context, message)
|
|
90
82
|
provider, source = response_identity
|
|
@@ -97,7 +97,7 @@ module Dependabot
|
|
|
97
97
|
timeout: TIMEOUTS::DEFAULT,
|
|
98
98
|
output_observer: nil
|
|
99
99
|
)
|
|
100
|
-
stdout = T.let("", String)
|
|
100
|
+
stdout = T.let(+"", String)
|
|
101
101
|
stderr = T.let("", String)
|
|
102
102
|
status = T.let(nil, T.nilable(ProcessStatus))
|
|
103
103
|
pid = T.let(nil, T.nilable(Integer))
|
|
@@ -172,10 +172,10 @@ module Dependabot
|
|
|
172
172
|
|
|
173
173
|
# 4. Append data to the appropriate stream
|
|
174
174
|
if io == stdout_io
|
|
175
|
-
stdout
|
|
175
|
+
stdout << data
|
|
176
176
|
else
|
|
177
177
|
stderr += data unless stderr_to_stdout
|
|
178
|
-
stdout
|
|
178
|
+
stdout << data if stderr_to_stdout
|
|
179
179
|
end
|
|
180
180
|
|
|
181
181
|
# Observe the output if an observer is provided.
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
# typed: strict
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require "excon"
|
|
5
|
+
require "sorbet-runtime"
|
|
6
|
+
require "uri"
|
|
7
|
+
|
|
8
|
+
require "dependabot/dependency"
|
|
9
|
+
require "dependabot/errors"
|
|
10
|
+
require "dependabot/shared_helpers"
|
|
11
|
+
|
|
12
|
+
module Dependabot
|
|
13
|
+
# Builds the allowlisted `error-context` hash sent alongside unknown errors so
|
|
14
|
+
# they can be debugged from Sentry without reproducing the job.
|
|
15
|
+
#
|
|
16
|
+
# The context is diagnostic only and must never affect error grouping. It is
|
|
17
|
+
# assembled exclusively from allowlisted keys: raw helper arguments, commands,
|
|
18
|
+
# stderr output and credentials are never forwarded.
|
|
19
|
+
module ErrorReportContext
|
|
20
|
+
extend T::Sig
|
|
21
|
+
|
|
22
|
+
Value = T.type_alias { T.any(String, Integer, Float, T::Boolean, T::Array[String]) }
|
|
23
|
+
Context = T.type_alias { T::Hash[String, Value] }
|
|
24
|
+
|
|
25
|
+
MAX_STRING_LENGTH = 500
|
|
26
|
+
MAX_ARRAY_LENGTH = 50
|
|
27
|
+
MAX_CAUSE_DEPTH = 5
|
|
28
|
+
REDACTED = "<redacted>"
|
|
29
|
+
|
|
30
|
+
# Maps the keys of a HasSentryContext error's `extra` hash that are safe to
|
|
31
|
+
# forward to their `error-context` key. Anything not listed (e.g. a helper's
|
|
32
|
+
# `args`, `command` or `stderr_output`) is dropped.
|
|
33
|
+
SENTRY_EXTRA_KEYS = T.let(
|
|
34
|
+
{
|
|
35
|
+
function: "helper-function",
|
|
36
|
+
process_exit_value: "helper-exit-status",
|
|
37
|
+
process_termsig: "helper-termsig",
|
|
38
|
+
time_taken: "helper-time-taken",
|
|
39
|
+
package_manager: "package-manager-name",
|
|
40
|
+
updated_files: "updated-files",
|
|
41
|
+
dependency_files: "dependency-files"
|
|
42
|
+
}.freeze,
|
|
43
|
+
T::Hash[Symbol, String]
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
ATTACHED_CONTEXT_IVAR = :@__dependabot_error_report_context
|
|
47
|
+
|
|
48
|
+
# Attaches context to any exception (including third-party ones such as Excon errors)
|
|
49
|
+
# so it can be reported if the exception is not handled. Keys are converted to
|
|
50
|
+
# kebab-case strings and values are normalised; unsupported values are dropped.
|
|
51
|
+
sig { params(error: Exception, context: T::Hash[T.any(String, Symbol), T.anything]).void }
|
|
52
|
+
def self.attach(error, context)
|
|
53
|
+
return if error.frozen?
|
|
54
|
+
|
|
55
|
+
merged = attached_context(error).merge(normalize(context))
|
|
56
|
+
error.instance_variable_set(ATTACHED_CONTEXT_IVAR, merged)
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
# Returns the context for an error and its causes, or nil when there is
|
|
60
|
+
# nothing to report. Context closer to the reported error takes precedence.
|
|
61
|
+
sig do
|
|
62
|
+
params(
|
|
63
|
+
error: Exception,
|
|
64
|
+
dependency: T.nilable(Dependabot::Dependency)
|
|
65
|
+
).returns(T.nilable(Context))
|
|
66
|
+
end
|
|
67
|
+
def self.build(error:, dependency: nil)
|
|
68
|
+
context = T.let({}, Context)
|
|
69
|
+
context.merge!(dependency_context(dependency)) if dependency
|
|
70
|
+
|
|
71
|
+
error_chain(error).reverse_each { |err| context.merge!(context_for_error(err)) }
|
|
72
|
+
context["cause-class"] = T.must(error.cause).class.name.to_s if error.cause
|
|
73
|
+
|
|
74
|
+
context.empty? ? nil : context
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
# Returns only the host of a URL: paths can contain private package or
|
|
78
|
+
# organisation names, and some registries embed tokens in them.
|
|
79
|
+
sig { params(url: String).returns(String) }
|
|
80
|
+
def self.host_for(url)
|
|
81
|
+
host = URI.parse(url).host
|
|
82
|
+
host.nil? || host.empty? ? REDACTED : truncate(host)
|
|
83
|
+
rescue URI::Error
|
|
84
|
+
REDACTED
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
sig { params(error: Exception).returns(Context) }
|
|
88
|
+
private_class_method def self.context_for_error(error)
|
|
89
|
+
context = T.let({}, Context)
|
|
90
|
+
context.merge!(excon_context(error))
|
|
91
|
+
context.merge!(sentry_extra_context(error))
|
|
92
|
+
if error.is_a?(Dependabot::SharedHelpers::HelperSubprocessFailed)
|
|
93
|
+
context["helper-error-class"] = truncate(error.error_class)
|
|
94
|
+
end
|
|
95
|
+
context.merge!(attached_context(error))
|
|
96
|
+
context
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
sig { params(error: Exception).returns(T::Array[Exception]) }
|
|
100
|
+
private_class_method def self.error_chain(error)
|
|
101
|
+
chain = T.let([error], T::Array[Exception])
|
|
102
|
+
while chain.length <= MAX_CAUSE_DEPTH
|
|
103
|
+
cause = T.must(chain.last).cause
|
|
104
|
+
break if cause.nil? || chain.include?(cause)
|
|
105
|
+
|
|
106
|
+
chain << cause
|
|
107
|
+
end
|
|
108
|
+
chain
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
sig { params(error: Exception).returns(Context) }
|
|
112
|
+
private_class_method def self.attached_context(error)
|
|
113
|
+
value = T.cast(error.instance_variable_get(ATTACHED_CONTEXT_IVAR), T.nilable(Context))
|
|
114
|
+
value || {}
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
sig { params(error: Exception).returns(Context) }
|
|
118
|
+
private_class_method def self.sentry_extra_context(error)
|
|
119
|
+
return {} unless error.is_a?(Dependabot::HasSentryContext)
|
|
120
|
+
|
|
121
|
+
extra = T.cast(error.sentry_context[:extra], Object)
|
|
122
|
+
return {} unless extra.is_a?(Hash)
|
|
123
|
+
|
|
124
|
+
context = T.let({}, Context)
|
|
125
|
+
SENTRY_EXTRA_KEYS.each do |source_key, target_key|
|
|
126
|
+
value = normalize_value(extra[source_key])
|
|
127
|
+
value = strip_pid(value) if source_key == :process_exit_value
|
|
128
|
+
context[target_key] = value unless value.nil?
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
names = dependency_names(extra[:dependencies])
|
|
132
|
+
context["dependency-names"] = names if names
|
|
133
|
+
context
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
sig { params(error: Exception).returns(Context) }
|
|
137
|
+
private_class_method def self.excon_context(error)
|
|
138
|
+
case error
|
|
139
|
+
when Excon::Error::Socket
|
|
140
|
+
{ "socket-error-class" => error.socket_error.class.name.to_s }
|
|
141
|
+
when Excon::Error::HTTPStatus
|
|
142
|
+
http_status_context(error)
|
|
143
|
+
else
|
|
144
|
+
{}
|
|
145
|
+
end
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
sig { params(error: Excon::Error::HTTPStatus).returns(Context) }
|
|
149
|
+
private_class_method def self.http_status_context(error)
|
|
150
|
+
context = T.let({}, Context)
|
|
151
|
+
request = T.cast(error.request, Object)
|
|
152
|
+
response = T.cast(error.response, Object)
|
|
153
|
+
|
|
154
|
+
if request.is_a?(Hash)
|
|
155
|
+
method = request[:method]
|
|
156
|
+
context["http-method"] = method.to_s.upcase if method
|
|
157
|
+
host = request[:host]
|
|
158
|
+
context["host"] = truncate(host) if host.is_a?(String)
|
|
159
|
+
end
|
|
160
|
+
status = response_status(response)
|
|
161
|
+
context["http-status"] = status if status
|
|
162
|
+
context
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
# Excon's own middleware wraps responses in Excon::Response, but status
|
|
166
|
+
# errors can also be built directly from a raw response hash.
|
|
167
|
+
sig { params(response: Object).returns(T.nilable(Integer)) }
|
|
168
|
+
private_class_method def self.response_status(response)
|
|
169
|
+
status = case response
|
|
170
|
+
when Excon::Response then response.status
|
|
171
|
+
when Hash then response[:status]
|
|
172
|
+
end
|
|
173
|
+
status.is_a?(Integer) ? status : nil
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
sig { params(dependency: Dependabot::Dependency).returns(Context) }
|
|
177
|
+
private_class_method def self.dependency_context(dependency)
|
|
178
|
+
normalize(
|
|
179
|
+
{
|
|
180
|
+
"dependency-name" => dependency.name,
|
|
181
|
+
"dependency-version" => dependency.version,
|
|
182
|
+
"dependency-previous-version" => dependency.previous_version,
|
|
183
|
+
"dependency-requirement-files" => dependency.requirements.filter_map { |req| req[:file] }.map(&:to_s).uniq
|
|
184
|
+
}
|
|
185
|
+
)
|
|
186
|
+
end
|
|
187
|
+
|
|
188
|
+
sig { params(dependencies: T.nilable(Object)).returns(T.nilable(T::Array[String])) }
|
|
189
|
+
private_class_method def self.dependency_names(dependencies)
|
|
190
|
+
return unless dependencies.is_a?(Array)
|
|
191
|
+
|
|
192
|
+
names = dependencies.filter_map do |dependency|
|
|
193
|
+
case dependency
|
|
194
|
+
when String then dependency
|
|
195
|
+
when Hash then (dependency["name"] || dependency[:name])&.to_s
|
|
196
|
+
when Dependabot::Dependency then dependency.name
|
|
197
|
+
end
|
|
198
|
+
end
|
|
199
|
+
names.empty? ? nil : names.uniq.first(MAX_ARRAY_LENGTH).map { |name| truncate(name) }
|
|
200
|
+
end
|
|
201
|
+
|
|
202
|
+
# `Process::Status#to_s` includes the (meaningless) pid, e.g. "pid 42 exit 1"
|
|
203
|
+
sig { params(value: T.nilable(Value)).returns(T.nilable(Value)) }
|
|
204
|
+
private_class_method def self.strip_pid(value)
|
|
205
|
+
value.is_a?(String) ? value.sub(/\Apid \d+ /, "") : value
|
|
206
|
+
end
|
|
207
|
+
|
|
208
|
+
sig { params(context: T::Hash[T.any(String, Symbol), T.anything]).returns(Context) }
|
|
209
|
+
private_class_method def self.normalize(context)
|
|
210
|
+
context.each_with_object(T.let({}, Context)) do |(key, value), normalized|
|
|
211
|
+
normalized_value = normalize_value(T.cast(value, T.nilable(Object)))
|
|
212
|
+
normalized[key.to_s.tr("_", "-")] = normalized_value unless normalized_value.nil?
|
|
213
|
+
end
|
|
214
|
+
end
|
|
215
|
+
|
|
216
|
+
sig { params(value: T.nilable(Object)).returns(T.nilable(Value)) }
|
|
217
|
+
private_class_method def self.normalize_value(value)
|
|
218
|
+
case value
|
|
219
|
+
when String then truncate(value)
|
|
220
|
+
when Symbol then truncate(value.to_s)
|
|
221
|
+
when Integer, true, false then value
|
|
222
|
+
# NaN and Infinity can't be serialised to JSON
|
|
223
|
+
when Float then value.finite? ? value : nil
|
|
224
|
+
when Array
|
|
225
|
+
strings = value.select { |item| item.is_a?(String) || item.is_a?(Symbol) }
|
|
226
|
+
strings.empty? ? nil : strings.first(MAX_ARRAY_LENGTH).map { |item| truncate(item.to_s) }
|
|
227
|
+
end
|
|
228
|
+
end
|
|
229
|
+
|
|
230
|
+
sig { params(value: String).returns(String) }
|
|
231
|
+
private_class_method def self.truncate(value)
|
|
232
|
+
value.length > MAX_STRING_LENGTH ? "#{value[0, MAX_STRING_LENGTH]}..." : value
|
|
233
|
+
end
|
|
234
|
+
end
|
|
235
|
+
end
|
data/lib/dependabot/errors.rb
CHANGED
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
# typed: strong
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require "json"
|
|
5
|
+
require "sorbet-runtime"
|
|
6
|
+
require "dependabot/dependency_file"
|
|
7
|
+
require "dependabot/errors"
|
|
8
|
+
|
|
9
|
+
module Dependabot
|
|
10
|
+
module FileParsers
|
|
11
|
+
class Hcl2JsonDocument
|
|
12
|
+
extend T::Sig
|
|
13
|
+
|
|
14
|
+
ObjectHash = T.type_alias { T::Hash[String, Object] }
|
|
15
|
+
ModuleBlocks = T.type_alias { T::Hash[String, T::Array[ObjectHash]] }
|
|
16
|
+
|
|
17
|
+
class Declaration
|
|
18
|
+
extend T::Sig
|
|
19
|
+
|
|
20
|
+
sig { params(name: String, fields: ObjectHash, path: String).void }
|
|
21
|
+
def initialize(name:, fields:, path:)
|
|
22
|
+
@name = name
|
|
23
|
+
@fields = fields
|
|
24
|
+
@path = path
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
sig { returns(String) }
|
|
28
|
+
attr_reader :name
|
|
29
|
+
|
|
30
|
+
sig { returns(T.nilable(String)) }
|
|
31
|
+
def version
|
|
32
|
+
optional_string("version")
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
protected
|
|
36
|
+
|
|
37
|
+
sig { params(key: String).returns(String) }
|
|
38
|
+
def string(key)
|
|
39
|
+
value = @fields[key]
|
|
40
|
+
return value if value.is_a?(String)
|
|
41
|
+
|
|
42
|
+
raise DependencyFileNotParseable.new(@path, "#{@name}.#{key} must be a string")
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
sig { params(key: String).returns(T.nilable(String)) }
|
|
46
|
+
def optional_string(key)
|
|
47
|
+
string(key) unless @fields[key].nil?
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
class ModuleDeclaration < Declaration
|
|
52
|
+
extend T::Sig
|
|
53
|
+
|
|
54
|
+
sig { returns(String) }
|
|
55
|
+
def source
|
|
56
|
+
string("source")
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
class ProviderDeclaration < Declaration
|
|
61
|
+
extend T::Sig
|
|
62
|
+
|
|
63
|
+
sig { returns(T.nilable(String)) }
|
|
64
|
+
def source
|
|
65
|
+
optional_string("source")
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
class DeprecatedProvider < T::ImmutableStruct
|
|
70
|
+
const :name, String
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
Provider = T.type_alias { T.any(ProviderDeclaration, DeprecatedProvider) }
|
|
74
|
+
|
|
75
|
+
sig { params(output: String, file: DependencyFile).returns(Hcl2JsonDocument) }
|
|
76
|
+
def self.from_helper_output(output, file:)
|
|
77
|
+
new(T.cast(JSON.parse(output), Object), file.path)
|
|
78
|
+
rescue JSON::ParserError => e
|
|
79
|
+
raise DependencyFileNotParseable.new(file.path, e.message)
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
sig { params(data: Object, path: String).void }
|
|
83
|
+
def initialize(data, path)
|
|
84
|
+
@path = path
|
|
85
|
+
@data = T.let(object(data, "root"), ObjectHash)
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
sig { params(overrides: T::Array[Hcl2JsonDocument]).returns(T::Array[ModuleDeclaration]) }
|
|
89
|
+
def module_declarations(overrides: [])
|
|
90
|
+
modules = module_blocks
|
|
91
|
+
overrides.each { |override| modules = merge_modules(override.module_blocks, modules) }
|
|
92
|
+
modules.map do |name, entries|
|
|
93
|
+
fields = entries.first
|
|
94
|
+
invalid!("module.#{name} must contain a block") unless fields
|
|
95
|
+
|
|
96
|
+
ModuleDeclaration.new(name: name, fields: fields, path: @path)
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
sig { returns(T::Array[Provider]) }
|
|
101
|
+
def provider_declarations
|
|
102
|
+
blocks("terraform").flat_map { |block| providers_for(block) }
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
sig { returns(T::Array[String]) }
|
|
106
|
+
def terragrunt_sources
|
|
107
|
+
blocks("terraform").filter_map do |block|
|
|
108
|
+
value = block["source"]
|
|
109
|
+
next unless value
|
|
110
|
+
|
|
111
|
+
invalid!("terraform.source must be a string") unless value.is_a?(String)
|
|
112
|
+
value
|
|
113
|
+
end
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
sig { returns(T::Hash[String, String]) }
|
|
117
|
+
def local_strings
|
|
118
|
+
blocks("locals").each_with_object(T.let({}, T::Hash[String, String])) do |block, result|
|
|
119
|
+
block.each { |name, value| result[name] = value if value.is_a?(String) }
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
sig { params(source: String).returns(T.nilable(String)) }
|
|
124
|
+
def provider_version(source)
|
|
125
|
+
value = @data["provider"]
|
|
126
|
+
return if value.nil?
|
|
127
|
+
|
|
128
|
+
entries = object(value, "provider")[source]
|
|
129
|
+
return if entries.nil?
|
|
130
|
+
|
|
131
|
+
entry = array(entries, "provider.#{source}").first
|
|
132
|
+
return if entry.nil?
|
|
133
|
+
|
|
134
|
+
version = object(entry, "provider.#{source}")["version"]
|
|
135
|
+
return if version.nil?
|
|
136
|
+
|
|
137
|
+
invalid!("provider.#{source}.version must be a string") unless version.is_a?(String)
|
|
138
|
+
version
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
protected
|
|
142
|
+
|
|
143
|
+
sig { returns(ModuleBlocks) }
|
|
144
|
+
def module_blocks
|
|
145
|
+
object(@data.fetch("module", {}), "module").to_h do |name, entries|
|
|
146
|
+
[name, array(entries, "module.#{name}").map { |entry| object(entry, "module.#{name}") }]
|
|
147
|
+
end
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
private
|
|
151
|
+
|
|
152
|
+
sig { params(overrides: ModuleBlocks, base: ModuleBlocks).returns(ModuleBlocks) }
|
|
153
|
+
def merge_modules(overrides, base)
|
|
154
|
+
merged = base.dup
|
|
155
|
+
overrides.each do |name, entries|
|
|
156
|
+
existing = merged[name]
|
|
157
|
+
merged[name] = if existing
|
|
158
|
+
fields = entries.first
|
|
159
|
+
invalid!("module.#{name} override must contain a block") unless fields
|
|
160
|
+
|
|
161
|
+
existing.map { |entry| entry.merge(fields) }
|
|
162
|
+
else
|
|
163
|
+
entries
|
|
164
|
+
end
|
|
165
|
+
end
|
|
166
|
+
merged
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
sig { params(block: ObjectHash).returns(T::Array[Provider]) }
|
|
170
|
+
def providers_for(block)
|
|
171
|
+
array(block.fetch("required_providers", []), "terraform.required_providers").flat_map do |group|
|
|
172
|
+
object(group, "required_providers").map do |name, value|
|
|
173
|
+
if value.is_a?(String)
|
|
174
|
+
DeprecatedProvider.new(name: name)
|
|
175
|
+
else
|
|
176
|
+
ProviderDeclaration.new(name: name, fields: object(value, "provider.#{name}"), path: @path)
|
|
177
|
+
end
|
|
178
|
+
end
|
|
179
|
+
end
|
|
180
|
+
end
|
|
181
|
+
|
|
182
|
+
sig { params(key: String).returns(T::Array[ObjectHash]) }
|
|
183
|
+
def blocks(key)
|
|
184
|
+
array(@data.fetch(key, []), key).map { |entry| object(entry, key) }
|
|
185
|
+
end
|
|
186
|
+
|
|
187
|
+
sig { params(value: Object, field: String).returns(ObjectHash) }
|
|
188
|
+
def object(value, field)
|
|
189
|
+
invalid!("#{field} must be an object") unless value.is_a?(Hash)
|
|
190
|
+
|
|
191
|
+
T.let(value, ObjectHash)
|
|
192
|
+
end
|
|
193
|
+
|
|
194
|
+
sig { params(value: Object, field: String).returns(T::Array[Object]) }
|
|
195
|
+
def array(value, field)
|
|
196
|
+
invalid!("#{field} must be an array") unless value.is_a?(Array)
|
|
197
|
+
|
|
198
|
+
value.map { |entry| T.cast(entry, Object) }
|
|
199
|
+
end
|
|
200
|
+
|
|
201
|
+
sig { params(message: String).returns(T.noreturn) }
|
|
202
|
+
def invalid!(message)
|
|
203
|
+
raise DependencyFileNotParseable.new(@path, message)
|
|
204
|
+
end
|
|
205
|
+
end
|
|
206
|
+
end
|
|
207
|
+
end
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
# typed: strong
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require "digest"
|
|
5
|
+
require "uri"
|
|
6
|
+
require "sorbet-runtime"
|
|
7
|
+
require "dependabot/errors"
|
|
8
|
+
require "dependabot/git_commit_checker"
|
|
9
|
+
require "dependabot/source"
|
|
10
|
+
|
|
11
|
+
module Dependabot
|
|
12
|
+
module FileParsers
|
|
13
|
+
module HclModuleSource
|
|
14
|
+
extend T::Sig
|
|
15
|
+
|
|
16
|
+
RequirementSource = T.type_alias { T::Hash[Symbol, T.nilable(String)] }
|
|
17
|
+
|
|
18
|
+
class Git < T::ImmutableStruct
|
|
19
|
+
extend T::Sig
|
|
20
|
+
|
|
21
|
+
const :url, String
|
|
22
|
+
const :ref, T.nilable(String)
|
|
23
|
+
const :proxy_url, T.nilable(String)
|
|
24
|
+
|
|
25
|
+
sig { params(module_name: String).returns(String) }
|
|
26
|
+
def dependency_name(module_name)
|
|
27
|
+
source = Source.from_url(url)
|
|
28
|
+
repository =
|
|
29
|
+
if source
|
|
30
|
+
"#{source.provider}::#{source.repo}"
|
|
31
|
+
else
|
|
32
|
+
"git_provider::repo_name/git_repo(#{Digest::SHA1.hexdigest(url)})"
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
[module_name, repository, ref].compact.join("::")
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
sig { returns(T.nilable(String)) }
|
|
39
|
+
def version
|
|
40
|
+
ref&.match(GitCommitChecker::VERSION_REGEX)&.named_captures&.fetch("version")
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
sig { returns(RequirementSource) }
|
|
44
|
+
def to_requirement_source
|
|
45
|
+
HclModuleSource.with_proxy_url({ type: "git", url: url, branch: nil, ref: ref }, proxy_url)
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
class Registry < T::ImmutableStruct
|
|
50
|
+
extend T::Sig
|
|
51
|
+
|
|
52
|
+
const :registry_hostname, String
|
|
53
|
+
const :module_identifier, String
|
|
54
|
+
const :proxy_url, T.nilable(String)
|
|
55
|
+
|
|
56
|
+
sig { returns(RequirementSource) }
|
|
57
|
+
def to_requirement_source
|
|
58
|
+
HclModuleSource.with_proxy_url(
|
|
59
|
+
{ type: "registry", registry_hostname: registry_hostname, module_identifier: module_identifier },
|
|
60
|
+
proxy_url
|
|
61
|
+
)
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
class UrlKind < T::Enum
|
|
66
|
+
enums do
|
|
67
|
+
HttpArchive = new("http_archive")
|
|
68
|
+
Mercurial = new("mercurial")
|
|
69
|
+
S3 = new("s3")
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
class Url < T::ImmutableStruct
|
|
74
|
+
extend T::Sig
|
|
75
|
+
|
|
76
|
+
const :url, String
|
|
77
|
+
const :kind, UrlKind
|
|
78
|
+
const :proxy_url, T.nilable(String)
|
|
79
|
+
|
|
80
|
+
sig { returns(RequirementSource) }
|
|
81
|
+
def to_requirement_source
|
|
82
|
+
HclModuleSource.with_proxy_url({ type: kind.serialize, url: url }, proxy_url)
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
class Interpolation < T::ImmutableStruct; end
|
|
87
|
+
|
|
88
|
+
Variant = T.type_alias { T.any(Git, Registry, Url) }
|
|
89
|
+
|
|
90
|
+
sig do
|
|
91
|
+
params(
|
|
92
|
+
source: String,
|
|
93
|
+
default_registry: String,
|
|
94
|
+
archive_extensions: T::Array[String],
|
|
95
|
+
proxy_url: T.nilable(String)
|
|
96
|
+
).returns(T.nilable(T.any(Variant, Interpolation)))
|
|
97
|
+
end
|
|
98
|
+
def self.parse(source, default_registry:, archive_extensions:, proxy_url:)
|
|
99
|
+
return Interpolation.new if interpolation?(source)
|
|
100
|
+
return if source.start_with?(".")
|
|
101
|
+
return git_from(source, proxy_url) if source.start_with?("github.com/", "bitbucket.org/", "git::", "git@")
|
|
102
|
+
|
|
103
|
+
kind = url_kind(source, archive_extensions)
|
|
104
|
+
return Url.new(url: source, kind: kind, proxy_url: proxy_url) if kind
|
|
105
|
+
|
|
106
|
+
registry_from(source, default_registry, proxy_url)
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
sig { params(source: String).returns(T::Boolean) }
|
|
110
|
+
def self.interpolation?(source)
|
|
111
|
+
source.include?("${")
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
sig { params(url: T.nilable(String)).returns(String) }
|
|
115
|
+
def self.terragrunt_name(url)
|
|
116
|
+
# Preserve the error for sources without a URL, such as a registry source.
|
|
117
|
+
Source.from_url(url)&.repo || T.must(url)
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
sig { params(fields: RequirementSource, proxy_url: T.nilable(String)).returns(RequirementSource) }
|
|
121
|
+
def self.with_proxy_url(fields, proxy_url)
|
|
122
|
+
fields[:proxy_url] = proxy_url if proxy_url
|
|
123
|
+
fields
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
sig { params(source: String, proxy_url: T.nilable(String)).returns(Git) }
|
|
127
|
+
def self.git_from(source, proxy_url)
|
|
128
|
+
url = source.strip.gsub(/^git::/, "")
|
|
129
|
+
url = "https://" + url unless url.start_with?("git@") || url.include?("://")
|
|
130
|
+
|
|
131
|
+
bare_uri =
|
|
132
|
+
if url.include?("git@")
|
|
133
|
+
T.must(url.split("git@").last).sub(":", "/")
|
|
134
|
+
else
|
|
135
|
+
url.sub(%r{(?:\w{3,5})?://}, "")
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
query = URI.parse("https://" + bare_uri).query
|
|
139
|
+
ref = URI.decode_www_form(query.to_s).to_h["ref"]&.split(%r{(?<!:)//})&.first
|
|
140
|
+
Git.new(url: T.must(url.gsub("?#{query}", "").split(%r{(?<!:)//}).first), ref: ref, proxy_url: proxy_url)
|
|
141
|
+
end
|
|
142
|
+
private_class_method :git_from
|
|
143
|
+
|
|
144
|
+
sig { params(source: String, default_registry: String, proxy_url: T.nilable(String)).returns(Registry) }
|
|
145
|
+
def self.registry_from(source, default_registry, proxy_url)
|
|
146
|
+
address = source.split("//").first
|
|
147
|
+
# Preserve the legacy error when the source has no address at all.
|
|
148
|
+
raise NoMethodError, "undefined method 'split' for nil" unless address
|
|
149
|
+
|
|
150
|
+
parts = address.split("/")
|
|
151
|
+
hostname, identifier =
|
|
152
|
+
case parts.length
|
|
153
|
+
when 3 then [default_registry, address]
|
|
154
|
+
when 4 then [parts.fetch(0), parts.drop(1).join("/")]
|
|
155
|
+
else raise DependencyFileNotEvaluatable, "Invalid registry source specified: '#{source}'"
|
|
156
|
+
end
|
|
157
|
+
Registry.new(registry_hostname: hostname.downcase, module_identifier: identifier.downcase, proxy_url: proxy_url)
|
|
158
|
+
end
|
|
159
|
+
private_class_method :registry_from
|
|
160
|
+
|
|
161
|
+
sig { params(source: String, archive_extensions: T::Array[String]).returns(T.nilable(UrlKind)) }
|
|
162
|
+
def self.url_kind(source, archive_extensions)
|
|
163
|
+
return UrlKind::Mercurial if source.start_with?("hg::")
|
|
164
|
+
return UrlKind::S3 if source.start_with?("s3::")
|
|
165
|
+
|
|
166
|
+
raise "Unknown src: #{source}" if source.split("/").first&.include?("::")
|
|
167
|
+
|
|
168
|
+
return unless source.start_with?("http")
|
|
169
|
+
return UrlKind::HttpArchive if http_archive?(source, archive_extensions)
|
|
170
|
+
|
|
171
|
+
raise "HTTP source, but not an archive!"
|
|
172
|
+
end
|
|
173
|
+
private_class_method :url_kind
|
|
174
|
+
|
|
175
|
+
sig { params(source: String, archive_extensions: T::Array[String]).returns(T::Boolean) }
|
|
176
|
+
def self.http_archive?(source, archive_extensions)
|
|
177
|
+
path_uri = URI.parse(T.must(source.split(%r{(?<!:)//}).first))
|
|
178
|
+
query_uri = URI.parse(source)
|
|
179
|
+
|
|
180
|
+
archive_extensions.any? { |ext| path_uri.path&.end_with?(ext) } || query_uri.query.to_s.include?("archive=")
|
|
181
|
+
end
|
|
182
|
+
private_class_method :http_archive?
|
|
183
|
+
end
|
|
184
|
+
end
|
|
185
|
+
end
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
require "sorbet-runtime"
|
|
5
5
|
|
|
6
6
|
require "dependabot/credential"
|
|
7
|
+
require "dependabot/error_report_context"
|
|
7
8
|
require "dependabot/notices"
|
|
8
9
|
|
|
9
10
|
module Dependabot
|
|
@@ -88,6 +89,21 @@ module Dependabot
|
|
|
88
89
|
updated_file.content = content
|
|
89
90
|
updated_file
|
|
90
91
|
end
|
|
92
|
+
|
|
93
|
+
# Builds the error raised when an update unexpectedly changes no files, with the
|
|
94
|
+
# dependency and file names attached as `error-context` to help debug it.
|
|
95
|
+
sig { params(message: String, context: T::Hash[Symbol, T.anything]).returns(RuntimeError) }
|
|
96
|
+
def no_files_changed_error(message, context = {})
|
|
97
|
+
error = RuntimeError.new(message)
|
|
98
|
+
Dependabot::ErrorReportContext.attach(
|
|
99
|
+
error,
|
|
100
|
+
{
|
|
101
|
+
dependency_names: dependencies.map(&:name),
|
|
102
|
+
dependency_files: dependency_files.map(&:name)
|
|
103
|
+
}.merge(context)
|
|
104
|
+
)
|
|
105
|
+
error
|
|
106
|
+
end
|
|
91
107
|
end
|
|
92
108
|
end
|
|
93
109
|
end
|
|
@@ -354,8 +354,9 @@ module Dependabot
|
|
|
354
354
|
|
|
355
355
|
# Change to the cloned repository directory
|
|
356
356
|
Dir.chdir(dir) do
|
|
357
|
-
# Fetch tags and their creation dates
|
|
358
|
-
|
|
357
|
+
# Fetch tags and their creation dates. Keep the time of day: a cooldown is compared in seconds,
|
|
358
|
+
# and a date without a time reads as midnight, which ends the cooldown up to a day early.
|
|
359
|
+
tags_command = 'git for-each-ref --format="%(refname:short) %(creatordate:iso)" refs/tags'
|
|
359
360
|
tags_stdout, stderr, process = Open3.capture3(env, tags_command)
|
|
360
361
|
|
|
361
362
|
return GitResponse.new(body: stderr, status: 500) unless process.success?
|
|
@@ -4,69 +4,33 @@
|
|
|
4
4
|
require "sorbet-runtime"
|
|
5
5
|
|
|
6
6
|
module Dependabot
|
|
7
|
-
# A
|
|
8
|
-
|
|
9
|
-
#
|
|
10
|
-
# {
|
|
11
|
-
# tag: "v1.2.0",
|
|
12
|
-
# version: Dependabot::Version.new("1.2.0"),
|
|
13
|
-
# commit_sha: "a1b2c3...",
|
|
14
|
-
# tag_sha: "d4e5f6..." # nil for lightweight tags
|
|
15
|
-
# }
|
|
16
|
-
#
|
|
17
|
-
# Distinct from Dependabot::GitTagWithDetail, which carries a tag name and
|
|
18
|
-
# release date for cooldown handling.
|
|
19
|
-
#
|
|
20
|
-
# Subclasses Hash so it is a drop-in replacement at the many call sites that
|
|
21
|
-
# read entries with [:key] / fetch, while exposing typed readers for the well-known
|
|
22
|
-
# keys. Instances compare equal (Hash#==) to plain hashes with the same
|
|
23
|
-
# content, so existing comparisons and API payloads are unaffected.
|
|
24
|
-
class GitTagDetails < Hash
|
|
7
|
+
# A tag or ref resolved by GitCommitChecker.
|
|
8
|
+
class GitTagDetails < T::ImmutableStruct
|
|
25
9
|
extend T::Sig
|
|
26
|
-
extend T::Generic
|
|
27
10
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
super()
|
|
42
|
-
self[:tag] = tag
|
|
43
|
-
self[:version] = version
|
|
44
|
-
self[:commit_sha] = commit_sha
|
|
45
|
-
self[:tag_sha] = tag_sha
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
# The tag or ref name, e.g. "v1.2.0".
|
|
49
|
-
sig { returns(String) }
|
|
50
|
-
def tag
|
|
51
|
-
T.cast(self[:tag], String)
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
# The version parsed from the tag name.
|
|
55
|
-
sig { returns(T.nilable(Gem::Version)) }
|
|
56
|
-
def version
|
|
57
|
-
T.cast(self[:version], T.nilable(Gem::Version))
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
# The SHA of the commit the tag points at.
|
|
61
|
-
sig { returns(T.nilable(String)) }
|
|
62
|
-
def commit_sha
|
|
63
|
-
T.cast(self[:commit_sha], T.nilable(String))
|
|
11
|
+
const :tag, String
|
|
12
|
+
const :version, T.nilable(Gem::Version), default: nil
|
|
13
|
+
const :commit_sha, T.nilable(String), default: nil
|
|
14
|
+
const :tag_sha, T.nilable(String), default: nil
|
|
15
|
+
|
|
16
|
+
sig { params(other: BasicObject).returns(T::Boolean) }
|
|
17
|
+
def ==(other)
|
|
18
|
+
case other
|
|
19
|
+
when GitTagDetails
|
|
20
|
+
to_h == other.to_h
|
|
21
|
+
else
|
|
22
|
+
false
|
|
23
|
+
end
|
|
64
24
|
end
|
|
65
25
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
26
|
+
sig { returns(T::Hash[Symbol, Object]) }
|
|
27
|
+
def to_h
|
|
28
|
+
{
|
|
29
|
+
tag: tag,
|
|
30
|
+
version: version,
|
|
31
|
+
commit_sha: commit_sha,
|
|
32
|
+
tag_sha: tag_sha
|
|
33
|
+
}
|
|
70
34
|
end
|
|
71
35
|
end
|
|
72
36
|
end
|
|
@@ -47,14 +47,6 @@ module Dependabot
|
|
|
47
47
|
raise_bad_response("GitLab", "#{context} #{key} must be a string")
|
|
48
48
|
end
|
|
49
49
|
|
|
50
|
-
sig { params(object: T::Hash[String, Object], key: String, context: String).returns(String) }
|
|
51
|
-
def object_string(object, key, context)
|
|
52
|
-
value = object[key]
|
|
53
|
-
return value if value.is_a?(String)
|
|
54
|
-
|
|
55
|
-
raise_bad_response("Azure", "#{context} #{key} must be a string")
|
|
56
|
-
end
|
|
57
|
-
|
|
58
50
|
sig { params(provider: String, message: String).returns(T.noreturn) }
|
|
59
51
|
def raise_bad_response(provider, message)
|
|
60
52
|
raise Dependabot::PrivateSourceBadResponse.new(
|
|
@@ -310,16 +310,7 @@ module Dependabot
|
|
|
310
310
|
def fetch_bitbucket_commits
|
|
311
311
|
bitbucket_client
|
|
312
312
|
.compare(T.must(source).repo, T.must(previous_tag), T.must(new_tag))
|
|
313
|
-
.map
|
|
314
|
-
summary = T.cast(commit.fetch("summary"), Dependabot::Clients::Bitbucket::JsonObject)
|
|
315
|
-
links = T.cast(commit.fetch("links"), Dependabot::Clients::Bitbucket::JsonObject)
|
|
316
|
-
html = T.cast(links.fetch("html"), Dependabot::Clients::Bitbucket::JsonObject)
|
|
317
|
-
{
|
|
318
|
-
message: T.cast(summary.fetch("raw"), String),
|
|
319
|
-
sha: T.cast(commit.fetch("hash"), String),
|
|
320
|
-
html_url: T.cast(html.fetch("href"), String)
|
|
321
|
-
}
|
|
322
|
-
end
|
|
313
|
+
.map(&:to_h)
|
|
323
314
|
rescue Dependabot::Clients::Bitbucket::NotFound,
|
|
324
315
|
Dependabot::Clients::Bitbucket::Unauthorized,
|
|
325
316
|
Dependabot::Clients::Bitbucket::Forbidden,
|
|
@@ -356,13 +347,7 @@ module Dependabot
|
|
|
356
347
|
type = git_sha?(new_tag) ? "commit" : "tag"
|
|
357
348
|
azure_client
|
|
358
349
|
.compare(previous_tag, new_tag, type)
|
|
359
|
-
.map
|
|
360
|
-
{
|
|
361
|
-
message: commit_response_parser.object_string(commit, "comment", "commit"),
|
|
362
|
-
sha: commit_response_parser.object_string(commit, "commitId", "commit"),
|
|
363
|
-
html_url: commit_response_parser.object_string(commit, "remoteUrl", "commit")
|
|
364
|
-
}
|
|
365
|
-
end
|
|
350
|
+
.map(&:to_h)
|
|
366
351
|
rescue Dependabot::Clients::Azure::NotFound,
|
|
367
352
|
Dependabot::Clients::Azure::Unauthorized,
|
|
368
353
|
Dependabot::Clients::Azure::Forbidden,
|
|
@@ -44,6 +44,12 @@ module Dependabot
|
|
|
44
44
|
end
|
|
45
45
|
end
|
|
46
46
|
|
|
47
|
+
sig { params(type: String).returns(T.nilable(T::Array[String])) }
|
|
48
|
+
def dependency_names(type)
|
|
49
|
+
value = @data[type]
|
|
50
|
+
object_hash(value, type).keys if value
|
|
51
|
+
end
|
|
52
|
+
|
|
47
53
|
sig { returns(T.nilable(String)) }
|
|
48
54
|
def name
|
|
49
55
|
value = @data["name"]
|
|
@@ -10,6 +10,11 @@ module Dependabot
|
|
|
10
10
|
|
|
11
11
|
ObjectHash = T.type_alias { T::Hash[String, Object] }
|
|
12
12
|
|
|
13
|
+
# Engines Dependabot reads (package managers and the Node.js language requirement). Other
|
|
14
|
+
# keys are free-form: npm accepts any value under engines, and tools like Apache Cordova
|
|
15
|
+
# store objects there (engines.cordovaDependencies).
|
|
16
|
+
KNOWN_ENGINES = %w(node npm yarn pnpm bun).freeze
|
|
17
|
+
|
|
13
18
|
const :package_manager, T.nilable(String), default: nil
|
|
14
19
|
const :engines, T.nilable(T::Hash[String, String]), default: nil
|
|
15
20
|
|
|
@@ -35,6 +40,7 @@ module Dependabot
|
|
|
35
40
|
engines = T.let({}, T::Hash[String, String])
|
|
36
41
|
object_hash(raw_engines, "engines").each do |name, raw_requirement|
|
|
37
42
|
next if raw_requirement.nil?
|
|
43
|
+
next if !raw_requirement.is_a?(String) && !KNOWN_ENGINES.include?(name)
|
|
38
44
|
|
|
39
45
|
raise TypeError, "engines.#{name} must be a string" unless raw_requirement.is_a?(String)
|
|
40
46
|
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
# frozen_string_literal: true
|
|
3
3
|
|
|
4
4
|
require "sorbet-runtime"
|
|
5
|
+
require "dependabot/error_report_context"
|
|
5
6
|
require "dependabot/shared_helpers"
|
|
6
7
|
|
|
7
8
|
# This class provides a thin wrapper around our normal usage of Excon as a simple HTTP client in order to
|
|
@@ -36,8 +37,7 @@ module Dependabot
|
|
|
36
37
|
retry_interval: 5
|
|
37
38
|
)
|
|
38
39
|
rescue Excon::Error::Timeout, Excon::Error::Socket => e
|
|
39
|
-
|
|
40
|
-
raise e
|
|
40
|
+
handle_request_error(e, http_method: "GET", url: url)
|
|
41
41
|
end
|
|
42
42
|
|
|
43
43
|
sig do
|
|
@@ -57,8 +57,7 @@ module Dependabot
|
|
|
57
57
|
**SharedHelpers.excon_defaults({ headers: headers }.merge(options))
|
|
58
58
|
)
|
|
59
59
|
rescue Excon::Error::Timeout, Excon::Error::Socket => e
|
|
60
|
-
|
|
61
|
-
raise e
|
|
60
|
+
handle_request_error(e, http_method: "HEAD", url: url)
|
|
62
61
|
end
|
|
63
62
|
|
|
64
63
|
sig { void }
|
|
@@ -66,6 +65,16 @@ module Dependabot
|
|
|
66
65
|
@cached_errors = {}
|
|
67
66
|
end
|
|
68
67
|
|
|
68
|
+
sig { params(error: CachedErrorType, http_method: String, url: String).returns(T.noreturn) }
|
|
69
|
+
private_class_method def self.handle_request_error(error, http_method:, url:)
|
|
70
|
+
# Replayed cached errors keep the context of the request that originally failed
|
|
71
|
+
raise error if cached_error_for(url).equal?(error)
|
|
72
|
+
|
|
73
|
+
cache_error(url, error) if cacheable_error?(error)
|
|
74
|
+
ErrorReportContext.attach(error, { http_method: http_method, host: ErrorReportContext.host_for(url) })
|
|
75
|
+
raise error
|
|
76
|
+
end
|
|
77
|
+
|
|
69
78
|
sig { params(url: String, error: CachedErrorType).void }
|
|
70
79
|
private_class_method def self.cache_error(url, error)
|
|
71
80
|
host = URI(url).host
|
|
@@ -624,8 +624,7 @@ module Dependabot
|
|
|
624
624
|
return nil if env.nil?
|
|
625
625
|
|
|
626
626
|
env.transform_keys(&:to_s).each_with_object({}) do |(key, value), result|
|
|
627
|
-
|
|
628
|
-
result[key] = if key.match?(/TOKEN/i)
|
|
627
|
+
result[key] = if key.match?(/TOKEN|(?:^|_)KEY\z/i)
|
|
629
628
|
"<redacted>"
|
|
630
629
|
else
|
|
631
630
|
value
|
data/lib/dependabot.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: dependabot-common
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.406.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Dependabot
|
|
@@ -518,6 +518,7 @@ files:
|
|
|
518
518
|
- lib/dependabot/clients/bitbucket.rb
|
|
519
519
|
- lib/dependabot/clients/bitbucket_with_retries.rb
|
|
520
520
|
- lib/dependabot/clients/codecommit.rb
|
|
521
|
+
- lib/dependabot/clients/comparison_commit.rb
|
|
521
522
|
- lib/dependabot/clients/github_release.rb
|
|
522
523
|
- lib/dependabot/clients/github_resource_parser.rb
|
|
523
524
|
- lib/dependabot/clients/github_with_retries.rb
|
|
@@ -540,6 +541,7 @@ files:
|
|
|
540
541
|
- lib/dependabot/dependency_requirement.rb
|
|
541
542
|
- lib/dependabot/ecosystem.rb
|
|
542
543
|
- lib/dependabot/error_details.rb
|
|
544
|
+
- lib/dependabot/error_report_context.rb
|
|
543
545
|
- lib/dependabot/errors.rb
|
|
544
546
|
- lib/dependabot/experiments.rb
|
|
545
547
|
- lib/dependabot/file_fetchers.rb
|
|
@@ -550,6 +552,8 @@ files:
|
|
|
550
552
|
- lib/dependabot/file_parsers/README.md
|
|
551
553
|
- lib/dependabot/file_parsers/base.rb
|
|
552
554
|
- lib/dependabot/file_parsers/base/dependency_set.rb
|
|
555
|
+
- lib/dependabot/file_parsers/hcl2_json_document.rb
|
|
556
|
+
- lib/dependabot/file_parsers/hcl_module_source.rb
|
|
553
557
|
- lib/dependabot/file_updaters.rb
|
|
554
558
|
- lib/dependabot/file_updaters/README.md
|
|
555
559
|
- lib/dependabot/file_updaters/artifact_updater.rb
|
|
@@ -635,7 +639,7 @@ licenses:
|
|
|
635
639
|
- MIT
|
|
636
640
|
metadata:
|
|
637
641
|
bug_tracker_uri: https://github.com/dependabot/dependabot-core/issues
|
|
638
|
-
changelog_uri: https://github.com/dependabot/dependabot-core/releases/tag/v0.
|
|
642
|
+
changelog_uri: https://github.com/dependabot/dependabot-core/releases/tag/v0.406.0
|
|
639
643
|
rdoc_options: []
|
|
640
644
|
require_paths:
|
|
641
645
|
- lib
|