 end
 
 defmodule NervesSystemCompatibility.Data do
-  alias NervesSystemCompatibility.API
-
-  @doc """
-  Returns compatibility information for Nerves Systems.
-  """
-  @spec get :: [%{binary => any}]
+  @type compatibility_data :: [%{binary => any}]
+
+  @spec get :: compatibility_data
   def get do
     nerves_br_version_to_metadata_map =
-      API.fetch_nerves_br_versions!()
+      NervesSystemCompatibility.API.fetch_nerves_br_versions!()
       |> Task.async_stream(&{&1, nerves_br_version_to_metadata(&1)}, timeout: 10_000)
       |> Enum.reduce(%{}, fn {:ok, {nerves_br_version, nerves_br_metadata}}, acc ->
         Map.put(acc, nerves_br_version, nerves_br_metadata)
       end)
 
-    API.fetch_nerves_system_versions!()
+    NervesSystemCompatibility.API.fetch_nerves_system_versions!()
     |> Task.async_stream(
       fn {target, versions} ->
         build_target_metadata(target, versions, nerves_br_version_to_metadata_map)

#!/usr/bin/env elixir

#
# Print the Nerves System compatibility information based on Nerves Project's
# Github repos. By default, the Github API only allows us 60 requests per hour.
# With an API token, we could get our rate limit bumped to 5000 requests an hour.
# See https://docs.github.com/en/rest/guides/getting-started-with-the-rest-api#authentication
#
# ## Usage
#
#   nerves_system_compatibility.exs
#
#   GITHUB_API_TOKEN=xxxxxx nerves_system_compatibility.exs
#

Mix.install([:req])

defmodule NervesSystemCompatibility do
  @doc """
  OTP versions that will be table rows.
  """
  @spec otp_versions :: [binary]
  def otp_versions do
    ~w[
      23.2.4
      23.2.7
      23.3.1
      24.0.2
      24.0.5
      24.1
      24.1.2
      24.1.4
      24.1.7
      24.2
      24.2.2
      24.3.2
      25.0
    ]
  end

  @doc """
  The Nerves System targets that are officially supported.
  """
  @spec target_systems :: [atom]
  def target_systems do
    ~w[
      bbb
      rpi
      rpi0
      rpi2
      rpi3
      rpi3a
      rpi4
      osd32mp1
      x86_64
      grisp2
    ]a
  end

  def run do
    NervesSystemCompatibility.Data.get()
    |> NervesSystemCompatibility.Table.build()
    |> IO.puts()
  end
end


  defp build_target_metadata(target, target_versions, %{} = nerves_br_version_to_metadata_map) do
    for target_version <- target_versions, into: [] do
      nerves_br_version =
        NervesSystemCompatibility.API.fetch_nerves_br_version_for_target!(target, target_version)
        |> Access.fetch!("nerves_br_version")

      if metadata_map = nerves_br_version_to_metadata_map[nerves_br_version] do
