Class: Dependabot::Docker::FileFetcher

Inherits:
FileFetchers::Base
  • Object
show all
Extended by:
T::Helpers, T::Sig
Defined in:
lib/dependabot/docker/file_fetcher.rb

Constant Summary collapse

YAML_REGEXP =
/^[^\.].*\.ya?ml$/i
DOCKER_REGEXP =
/dockerfile/i

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.required_files_in?(filenames) ⇒ Boolean

Returns:

  • (Boolean)


18
19
20
21
# File 'lib/dependabot/docker/file_fetcher.rb', line 18

def self.required_files_in?(filenames)
  filenames.any? { |f| f.match?(DOCKER_REGEXP) } or
    filenames.any? { |f| f.match?(YAML_REGEXP) }
end

.required_files_messageObject



23
24
25
# File 'lib/dependabot/docker/file_fetcher.rb', line 23

def self.required_files_message
  "Repo must contain a Dockerfile or Kubernetes YAML files."
end

Instance Method Details

#fetch_filesObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/dependabot/docker/file_fetcher.rb', line 28

def fetch_files
  fetched_files = []
  fetched_files += correctly_encoded_dockerfiles
  fetched_files += correctly_encoded_yamlfiles

  return fetched_files if fetched_files.any?

  if incorrectly_encoded_dockerfiles.none? && incorrectly_encoded_yamlfiles.none?
    raise Dependabot::DependencyFileNotFound.new(
      File.join(directory, "Dockerfile"),
      "No Dockerfiles nor Kubernetes YAML found in #{directory}"
    )
  elsif incorrectly_encoded_dockerfiles.none?
    raise(
      Dependabot::DependencyFileNotParseable,
      incorrectly_encoded_yamlfiles.first.path
    )
  else
    raise(
      Dependabot::DependencyFileNotParseable,
      incorrectly_encoded_dockerfiles.first.path
    )
  end
end