Sha256: 4e98fb35d8f382d6e4fe54321e2355a8024aa33c4eb969ce03659b6a589aa1e5

Contents?: true

Size: 1.67 KB

Versions: 928

Compression:

Stored size: 1.67 KB

Contents

defmodule DependencyHelper do
  def main() do
    IO.read(:stdio, :all)
    |> Jason.decode!()
    |> run()
    |> case do
      {output, 0} ->
        if output =~ "No authenticated organization found" do
          {:error, output}
        else
          {:ok, :erlang.binary_to_term(output)}
        end

      {error, 1} -> {:error, error}
    end
    |> handle_result()
  end

  defp handle_result({:ok, {:ok, result}}) do
    encode_and_write(%{"result" => result})
  end

  defp handle_result({:ok, {:error, reason}}) do
    encode_and_write(%{"error" => reason})
    System.halt(1)
  end

  defp handle_result({:error, reason}) do
    encode_and_write(%{"error" => reason})
    System.halt(1)
  end

  defp encode_and_write(content) do
    content
    |> Jason.encode!()
    |> IO.write()
  end

  defp run(%{"function" => "parse", "args" => [dir]}) do
    run_script("parse_deps.exs", dir)
  end

  defp run(%{"function" => "get_latest_resolvable_version", "args" => [dir, dependency_name, credentials]}) do
    run_script("check_update.exs", dir, [dependency_name] ++ credentials)
  end

  defp run(%{"function" => "get_updated_lockfile", "args" => [dir, dependency_name, credentials]}) do
    run_script("do_update.exs", dir, [dependency_name] ++ credentials)
  end

  defp run_script(script, dir, args \\ []) do
    args = [
      "run",
      "--no-deps-check",
      "--no-start",
      "--no-compile",
      "--no-elixir-version-check",
      script
    ] ++ args

    System.cmd(
      "mix",
      args,
      [
        cd: dir,
        env: %{
          "MIX_EXS" => nil,
          "MIX_LOCK" => nil,
          "MIX_DEPS" => nil
        }
      ]
    )
  end
end

DependencyHelper.main()

Version data entries

928 entries across 926 versions & 2 rubygems

Version Path
dependabot-hex-0.213.0 helpers/lib/run.exs
dependabot-hex-0.212.0 helpers/lib/run.exs
dependabot-hex-0.211.0 helpers/lib/run.exs
dependabot-hex-0.210.0 helpers/lib/run.exs
dependabot-hex-0.209.0 helpers/lib/run.exs
dependabot-hex-0.208.0 helpers/lib/run.exs
dependabot-hex-0.207.0 helpers/lib/run.exs
dependabot-hex-0.206.0 helpers/lib/run.exs
dependabot-hex-0.205.1 helpers/lib/run.exs
dependabot-hex-0.205.0 helpers/lib/run.exs
dependabot-hex-0.204.0 helpers/lib/run.exs
dependabot-hex-0.203.0 helpers/lib/run.exs
dependabot-hex-0.202.0 helpers/lib/run.exs
dependabot-hex-0.201.1 helpers/lib/run.exs
dependabot-hex-0.201.0 helpers/lib/run.exs
dependabot-hex-0.200.0 helpers/lib/run.exs
dependabot-hex-0.199.0 helpers/lib/run.exs
dependabot-hex-0.198.0 helpers/lib/run.exs
dependabot-hex-0.197.0 helpers/lib/run.exs
dependabot-hex-0.196.4 helpers/lib/run.exs