class Dependabot::GitSubmodules::FileFetcher

Public Class Methods

required_files_in?(filenames) click to toggle source
# File lib/dependabot/git_submodules/file_fetcher.rb, line 11
def self.required_files_in?(filenames)
  filenames.include?(".gitmodules")
end
required_files_message() click to toggle source
# File lib/dependabot/git_submodules/file_fetcher.rb, line 15
def self.required_files_message
  "Repo must contain a .gitmodules file."
end

Private Instance Methods

fetch_files() click to toggle source
# File lib/dependabot/git_submodules/file_fetcher.rb, line 21
def fetch_files
  fetched_files = []
  fetched_files << gitmodules_file
  fetched_files += submodule_refs
  fetched_files
end
fetch_github_submodule_commit(path) click to toggle source
# File lib/dependabot/git_submodules/file_fetcher.rb, line 70
def fetch_github_submodule_commit(path)
  content = github_client.contents(
    repo,
    path: path,
    ref: commit
  )
  raise Dependabot::DependencyFileNotFound, path if content.is_a?(Array) || content.type != "submodule"

  content.sha
end
fetch_submodule_ref_from_host(submodule_path) click to toggle source
# File lib/dependabot/git_submodules/file_fetcher.rb, line 48
def fetch_submodule_ref_from_host(submodule_path)
  path = Pathname.new(File.join(directory, submodule_path)).
         cleanpath.to_path.gsub(%r{^/*}, "")
  sha =  case source.provider
         when "github"
           fetch_github_submodule_commit(path)
         when "gitlab"
           tmp_path = path.gsub(%r{^/*}, "")
           gitlab_client.get_file(repo, tmp_path, commit).blob_id
         else raise "Unsupported provider '#{source.provider}'."
         end

  DependencyFile.new(
    name: Pathname.new(submodule_path).cleanpath.to_path,
    content: sha,
    directory: directory,
    type: "submodule"
  )
rescue Octokit::NotFound, Gitlab::Error::NotFound
  raise Dependabot::DependencyFileNotFound, path
end
gitmodules_file() click to toggle source
# File lib/dependabot/git_submodules/file_fetcher.rb, line 28
def gitmodules_file
  @gitmodules_file ||= fetch_file_from_host(".gitmodules")
end
submodule_paths() click to toggle source
# File lib/dependabot/git_submodules/file_fetcher.rb, line 40
def submodule_paths
  @submodule_paths ||=
    Dependabot::SharedHelpers.in_a_temporary_directory do
      File.write(".gitmodules", gitmodules_file.content)
      ParseConfig.new(".gitmodules").params.values.map { |p| p["path"] }
    end
end
submodule_refs() click to toggle source
# File lib/dependabot/git_submodules/file_fetcher.rb, line 32
def submodule_refs
  @submodule_refs ||=
    submodule_paths.
    map { |path| fetch_submodule_ref_from_host(path) }.
    tap { |refs| refs.each { |f| f.support_file = true } }.
    uniq
end