Class: Dependabot::Gradle::Package::DistributionsFetcher

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/dependabot/gradle/package/distributions_fetcher.rb

Class Method Summary collapse

Class Method Details

.available_versionsObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/dependabot/gradle/package/distributions_fetcher.rb', line 18

def self.available_versions
  return @available_versions if @available_versions.any?

  response = Dependabot::RegistryClient.get(url: "https://services.gradle.org/versions/all")
  versions = T.let(
    JSON.parse(
      T.let(response.body, String),
      object_class: OpenStruct
    ),
    T::Array[OpenStruct]
  )
  @available_versions +=
    versions
    .select { |v| release_version?(version: v) }
    .uniq { |v| v[:version] }
    .map do |v|
      {
        version: v[:version],
        build_time: v[:buildTime]
      }
    end
end

.resolve_checksum(distribution_url) ⇒ Object



52
53
54
55
56
57
58
59
60
61
# File 'lib/dependabot/gradle/package/distributions_fetcher.rb', line 52

def self.resolve_checksum(distribution_url)
  cached = @distributions_checksums[distribution_url]
  return cached if cached

  checksum_url = "#{distribution_url}.sha256"
  checksum = T.let(Dependabot::RegistryClient.get(url: checksum_url).body, String).strip
  return nil unless checksum.match?(/\A[a-f0-9]{64}\z/)

  @distributions_checksums[distribution_url] = [checksum_url, checksum]
end