class Dependabot::Hex::FileFetcher

Constants

APPS_PATH_REGEX
PATH_DEPS_REGEX
STRING_ARG
SUPPORTED_METHODS
SUPPORT_FILE

Public Class Methods

required_files_in?(filenames) click to toggle source
# File lib/dependabot/hex/file_fetcher.rb, line 16
def self.required_files_in?(filenames)
  filenames.include?("mix.exs")
end
required_files_message() click to toggle source
# File lib/dependabot/hex/file_fetcher.rb, line 20
def self.required_files_message
  "Repo must contain a mix.exs."
end

Private Instance Methods

fetch_files() click to toggle source
# File lib/dependabot/hex/file_fetcher.rb, line 26
def fetch_files
  fetched_files = []
  fetched_files << mixfile
  fetched_files << lockfile if lockfile
  fetched_files += subapp_mixfiles
  fetched_files += support_files
  fetched_files
end
lockfile() click to toggle source
# File lib/dependabot/hex/file_fetcher.rb, line 39
def lockfile
  return @lockfile if @lockfile_lookup_attempted

  @lockfile_lookup_attempted = true
  @lockfile ||= fetch_file_from_host("mix.lock")
rescue Dependabot::DependencyFileNotFound
  nil
end
mixfile() click to toggle source
# File lib/dependabot/hex/file_fetcher.rb, line 35
def mixfile
  @mixfile ||= fetch_file_from_host("mix.exs")
end
sub_project_directories() click to toggle source
# File lib/dependabot/hex/file_fetcher.rb, line 58
def sub_project_directories
  mixfile.content.scan(PATH_DEPS_REGEX).flatten
end
subapp_mixfiles() click to toggle source
# File lib/dependabot/hex/file_fetcher.rb, line 62
def subapp_mixfiles
  subapp_directories = []
  subapp_directories += umbrella_app_directories
  subapp_directories += sub_project_directories

  subapp_directories.map do |dir|
    fetch_file_from_host("#{dir}/mix.exs")
  rescue Dependabot::DependencyFileNotFound
    # If the folder doesn't have a mix.exs it *might* be because it's
    # not an app. Ignore the fact we couldn't fetch one and proceed with
    # updating (it will blow up later if there are problems)
    nil
  end.compact
rescue Octokit::NotFound, Gitlab::Error::NotFound
  # If the path specified in apps_path doesn't exist then it's not being
  # used. We can just return an empty array of subapp files.
  []
end
support_files() click to toggle source
# File lib/dependabot/hex/file_fetcher.rb, line 81
def support_files
  mixfile.content.scan(SUPPORT_FILE).map do |support_file_args|
    path = Pathname.new(File.join(*support_file_args.compact.reverse)).
           cleanpath.to_path
    fetch_file_from_host(path).tap { |f| f.support_file = true }
  end
end
umbrella_app_directories() click to toggle source
# File lib/dependabot/hex/file_fetcher.rb, line 48
def umbrella_app_directories
  apps_path = mixfile.content.match(APPS_PATH_REGEX)&.
              named_captures&.fetch("path")
  return [] unless apps_path

  repo_contents(dir: apps_path).
    select { |f| f.type == "dir" }.
    map { |f| File.join(apps_path, f.name) }
end