class Dependabot::Hex::MetadataFinder

Constants

SOURCE_KEYS

Private Instance Methods

find_source_from_git_url() click to toggle source
# File lib/dependabot/hex/metadata_finder.rb, line 48
def find_source_from_git_url
  info = dependency.requirements.map { |r| r[:source] }.compact.first

  url = info[:url] || info.fetch("url")
  Source.from_url(url)
end
find_source_from_hex_listing() click to toggle source
# File lib/dependabot/hex/metadata_finder.rb, line 38
def find_source_from_hex_listing
  potential_source_urls =
    SOURCE_KEYS.
    map { |key| hex_listing.dig("meta", "links", key) }.
    compact

  source_url = potential_source_urls.find { |url| Source.from_url(url) }
  Source.from_url(source_url)
end
hex_listing() click to toggle source
# File lib/dependabot/hex/metadata_finder.rb, line 55
def hex_listing
  return @hex_listing unless @hex_listing.nil?

  response = Excon.get(
    "https://hex.pm/api/packages/#{dependency.name}",
    idempotent: true,
    **SharedHelpers.excon_defaults
  )

  @hex_listing = JSON.parse(response.body)
end
look_up_source() click to toggle source
# File lib/dependabot/hex/metadata_finder.rb, line 20
def look_up_source
  case new_source_type
  when "default" then find_source_from_hex_listing
  when "git" then find_source_from_git_url
  else raise "Unexpected source type: #{new_source_type}"
  end
end
new_source_type() click to toggle source
# File lib/dependabot/hex/metadata_finder.rb, line 28
def new_source_type
  sources =
    dependency.requirements.map { |r| r.fetch(:source) }.uniq.compact

  return "default" if sources.empty?
  raise "Multiple sources! #{sources.join(', ')}" if sources.count > 1

  sources.first[:type] || sources.first.fetch("type")
end