Class: Dependabot::Shared::SharedFileFetcher
- Inherits:
-
FileFetchers::Base
- Object
- FileFetchers::Base
- Dependabot::Shared::SharedFileFetcher
- Extended by:
- T::Helpers, T::Sig
- Defined in:
- lib/dependabot/shared/shared_file_fetcher.rb
Direct Known Subclasses
Constant Summary collapse
- YAML_REGEXP =
/^[^\.].*\.ya?ml$/i
Class Method Summary collapse
Instance Method Summary collapse
- #correctly_encoded_yamlfiles ⇒ Object
- #fetch_files ⇒ Object
- #incorrectly_encoded_yamlfiles ⇒ Object
- #raise_appropriate_error(incorrectly_encoded_files = []) ⇒ Object
- #yamlfiles ⇒ Object
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
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/dependabot/shared/shared_file_fetcher.rb', line 34 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 # This doesn't handle multi-resource files, but it shouldn't matter, since the first resource # in a multi-resource file had better be a valid k8s resource content = YAML.safe_load(T.must(f.content), aliases: true) likely_kubernetes_resource?(content) end rescue ::Psych::Exception false end end |
#fetch_files ⇒ Object
28 29 30 31 |
# File 'lib/dependabot/shared/shared_file_fetcher.rb', line 28 def fetch_files fetched_files = [] fetched_files + correctly_encoded_yamlfiles end |
#incorrectly_encoded_yamlfiles ⇒ Object
51 52 53 |
# File 'lib/dependabot/shared/shared_file_fetcher.rb', line 51 def incorrectly_encoded_yamlfiles yamlfiles.reject { |f| f.content&.valid_encoding? } end |
#raise_appropriate_error(incorrectly_encoded_files = []) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/dependabot/shared/shared_file_fetcher.rb', line 60 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
75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/dependabot/shared/shared_file_fetcher.rb', line 75 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) # The YAML parser used doesn't properly handle a byte-order-mark (BOM) and it can cause failures in # unexpected ways. That BOM is removed here to allow regular updates to proceed. fetched.content = T.must(fetched.content)[1..-1] if fetched.content&.start_with?("\uFEFF") fetched end, T.nilable(T::Array[DependencyFile]) ) end |