Skip to content

Commit

Permalink
Strict-type-Dependabot::Hex::MetaDateFinder. (#9913)
Browse files Browse the repository at this point in the history
  • Loading branch information
raj-meka authored Jun 6, 2024
1 parent 0bc6abb commit 0d29e45
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions hex/lib/dependabot/hex/metadata_finder.rb
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
# typed: true
# typed: strict
# frozen_string_literal: true

require "excon"
require "dependabot/metadata_finders"
require "dependabot/metadata_finders/base"
require "dependabot/registry_client"
require "sorbet-runtime"

module Dependabot
module Hex
class MetadataFinder < Dependabot::MetadataFinders::Base
SOURCE_KEYS = %w(
extend T::Sig

SOURCE_KEYS = T.let(%w(
GitHub Github github
GitLab Gitlab gitlab
BitBucket Bitbucket bitbucket
Source source
).freeze
).freeze, T::Array[String])

private

sig { override.returns(T.nilable(Dependabot::Source)) }
def look_up_source
case new_source_type
when "default" then find_source_from_hex_listing
Expand All @@ -26,31 +30,35 @@ def look_up_source
end
end

sig { returns(T.nilable(String)) }
def new_source_type
dependency.source_type
end

sig { returns(T.nilable(Dependabot::Source)) }
def find_source_from_hex_listing
potential_source_urls =
SOURCE_KEYS
.filter_map { |key| hex_listing.dig("meta", "links", key) }
.filter_map { |key| T.must(hex_listing).dig("meta", "links", key) }

source_url = potential_source_urls.find { |url| Source.from_url(url) }
Source.from_url(source_url)
end

sig { returns(T.nilable(Dependabot::Source)) }
def find_source_from_git_url
info = dependency.requirements.filter_map { |r| r[:source] }.first

url = info[:url] || info.fetch("url")
Source.from_url(url)
end

sig { returns(T.nilable(T::Hash[String, T.untyped])) }
def hex_listing
return @hex_listing unless @hex_listing.nil?

response = Dependabot::RegistryClient.get(url: "https://hex.pm/api/packages/#{dependency.name}")
@hex_listing = JSON.parse(response.body)
@hex_listing = T.let(JSON.parse(response.body), T.nilable(T::Hash[String, T.untyped]))
end
end
end
Expand Down

0 comments on commit 0d29e45

Please sign in to comment.