Class: Dependabot::Shared::SharedFileFetcher
- Inherits:
-
FileFetchers::Base
- Object
- FileFetchers::Base
- Dependabot::Shared::SharedFileFetcher
show all
- Extended by:
- T::Helpers, T::Sig
- Defined in:
- lib/dependabot/shared/shared_file_fetcher.rb
Constant Summary
collapse
- YAML_REGEXP =
/^[^\.].*\.ya?ml$/i
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.filename_regex ⇒ Object
20
|
# File 'lib/dependabot/shared/shared_file_fetcher.rb', line 20
def self.filename_regex; end
|
.required_files_in?(filenames) ⇒ Boolean
23
24
25
|
# File 'lib/dependabot/shared/shared_file_fetcher.rb', line 23
def self.required_files_in?(filenames)
filenames.any? { |f| f.match?(filename_regex) }
end
|
Instance Method Details
#correctly_encoded_yamlfiles ⇒ Object
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/dependabot/shared/shared_file_fetcher.rb', line 28
def correctly_encoded_yamlfiles
candidate_files = yamlfiles.select { |f| f.content&.valid_encoding? }
candidate_files.select do |f|
if f.type == "file" && Utils.likely_helm_chart?(f)
true
else
content = YAML.safe_load(T.must(f.content), aliases: true)
likely_kubernetes_resource?(content)
end
rescue ::Psych::Exception
false
end
end
|
#fetch_files ⇒ Object
85
86
87
88
|
# File 'lib/dependabot/shared/shared_file_fetcher.rb', line 85
def fetch_files
fetched_files = []
fetched_files + correctly_encoded_yamlfiles
end
|
#incorrectly_encoded_yamlfiles ⇒ Object
45
46
47
|
# File 'lib/dependabot/shared/shared_file_fetcher.rb', line 45
def incorrectly_encoded_yamlfiles
yamlfiles.reject { |f| f.content&.valid_encoding? }
end
|
#raise_appropriate_error(incorrectly_encoded_files = []) ⇒ Object
54
55
56
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/dependabot/shared/shared_file_fetcher.rb', line 54
def raise_appropriate_error(
incorrectly_encoded_files = []
)
if incorrectly_encoded_files.none? && incorrectly_encoded_yamlfiles.none?
raise Dependabot::DependencyFileNotFound.new(
File.join(directory, "Dockerfile"),
"No Dockerfiles nor Kubernetes YAML found in #{directory}"
)
end
invalid_files = incorrectly_encoded_files.any? ? incorrectly_encoded_files : incorrectly_encoded_yamlfiles
raise Dependabot::DependencyFileNotParseable, T.must(invalid_files.first).path
end
|
#yamlfiles ⇒ Object
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
# File 'lib/dependabot/shared/shared_file_fetcher.rb', line 69
def yamlfiles
@yamlfiles ||= T.let(
repo_contents(raise_errors: false)
.select { |f| f.type == "file" && f.name.match?(YAML_REGEXP) }
.map do |f|
fetched = fetch_file_from_host(f.name)
fetched.content = T.must(fetched.content)[1..-1] if fetched.content&.start_with?("\uFEFF")
fetched
end,
T.nilable(T::Array[DependencyFile])
)
end
|