class Dependabot::GitSubmodules::FileParser

Public Instance Methods

parse() click to toggle source
# File lib/dependabot/git_submodules/file_parser.rb, line 12
def parse
  Dependabot::SharedHelpers.in_a_temporary_directory do
    File.write(".gitmodules", gitmodules_file.content)

    ParseConfig.new(".gitmodules").params.map do |_, params|
      raise DependencyFileNotParseable, gitmodules_file.path if params.fetch("path").end_with?("/")

      Dependency.new(
        name: params.fetch("path"),
        version: submodule_sha(params.fetch("path")),
        package_manager: "submodules",
        requirements: [{
          requirement: nil,
          file: ".gitmodules",
          source: {
            type: "git",
            url: absolute_url(params["url"]),
            branch: params["branch"],
            ref: params["branch"]
          },
          groups: []
        }]
      )
    end
  end
end

Private Instance Methods

absolute_url(url) click to toggle source
# File lib/dependabot/git_submodules/file_parser.rb, line 41
def absolute_url(url)
  # Submodules can be specified with a relative URL (e.g., ../repo.git)
  # which we want to expand out into a full URL if present.
  return url unless url.start_with?("../", "./")

  path = Pathname.new(File.join(source.repo, url))
  "https://#{source.hostname}/#{path.cleanpath}"
end
check_required_files() click to toggle source
# File lib/dependabot/git_submodules/file_parser.rb, line 61
def check_required_files
  %w(.gitmodules).each do |filename|
    raise "No #{filename}!" unless get_original_file(filename)
  end
end
gitmodules_file() click to toggle source
# File lib/dependabot/git_submodules/file_parser.rb, line 57
def gitmodules_file
  @gitmodules_file ||= get_original_file(".gitmodules")
end
submodule_sha(path) click to toggle source
# File lib/dependabot/git_submodules/file_parser.rb, line 50
def submodule_sha(path)
  submodule = dependency_files.find { |f| f.name == path }
  raise "Submodule not found #{path}" unless submodule

  submodule.content
end