Class: Dependabot::Helm::FileFetcher

Inherits:
Shared::SharedFileFetcher
  • Object
show all
Defined in:
lib/dependabot/helm/file_fetcher.rb

Constant Summary collapse

FILENAME_REGEX =
/.*\.ya?ml$/i
CHART_LOCK_REGEXP =
/Chart\.lock/i

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.filename_regexObject



24
25
26
# File 'lib/dependabot/helm/file_fetcher.rb', line 24

def self.filename_regex
  FILENAME_REGEX
end

.required_files_messageObject



61
62
63
# File 'lib/dependabot/helm/file_fetcher.rb', line 61

def self.required_files_message
  "Repo must contain a Helm charts file."
end

Instance Method Details

#chart_locksObject



40
41
42
43
44
45
46
47
48
# File 'lib/dependabot/helm/file_fetcher.rb', line 40

def chart_locks
  @chart_locks ||=
    T.let(
      repo_contents(raise_errors: false)
                .select { |f| f.type == "file" && f.name.match?(CHART_LOCK_REGEXP) }
                .map { |f| fetch_file_from_host(f.name) },
      T.nilable(T::Array[DependencyFile])
    )
end

#correctly_encoded_helm_filesObject



51
52
53
# File 'lib/dependabot/helm/file_fetcher.rb', line 51

def correctly_encoded_helm_files
  helm_files.select { |f| T.must(f.content).valid_encoding? }
end

#fetch_filesObject



13
14
15
16
17
18
19
20
21
# File 'lib/dependabot/helm/file_fetcher.rb', line 13

def fetch_files
  fetched_files = []
  fetched_files += correctly_encoded_helm_files
  fetched_files += chart_locks

  return fetched_files if fetched_files.any?

  raise_appropriate_error
end

#helm_filesObject



29
30
31
32
33
34
35
36
37
# File 'lib/dependabot/helm/file_fetcher.rb', line 29

def helm_files
  @helm_files ||=
    T.let(
      repo_contents(raise_errors: false)
                .select { |f| f.type == "file" && f.name.match?(FILENAME_REGEX) }
                .map { |f| fetch_file_from_host(f.name) },
      T.nilable(T::Array[DependencyFile])
    )
end

#incorrectly_encoded_helm_files_filesObject



56
57
58
# File 'lib/dependabot/helm/file_fetcher.rb', line 56

def incorrectly_encoded_helm_files_files
  helm_files.reject { |f| T.must(f.content).valid_encoding? }
end