Class: Dependabot::Nix::FileParser

Inherits:
FileParsers::Base
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/dependabot/nix/file_parser.rb

Constant Summary collapse

SUPPORTED_SOURCE_TYPES =

Source types that are backed by git and can be updated via revision tracking

T.let(%w(github gitlab sourcehut git).freeze, T::Array[String])
SUPPORTED_LOCK_VERSION =
7
DEFAULT_HOSTS =
T.let(
  {
    "github" => "github.com",
    "gitlab" => "gitlab.com",
    "sourcehut" => "git.sr.ht"
  }.freeze,
  T::Hash[String, String]
)

Instance Method Summary collapse

Instance Method Details

#ecosystemObject



57
58
59
60
61
62
63
64
65
# File 'lib/dependabot/nix/file_parser.rb', line 57

def ecosystem
  @ecosystem ||= T.let(
    Ecosystem.new(
      name: ECOSYSTEM,
      package_manager: package_manager
    ),
    T.nilable(Dependabot::Ecosystem)
  )
end

#parseObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/dependabot/nix/file_parser.rb', line 33

def parse
  lock_content = JSON.parse(T.must(flake_lock.content))

  lock_version = lock_content["version"]
  if lock_version != SUPPORTED_LOCK_VERSION
    Dependabot.logger.warn(
      "flake.lock version #{lock_version.inspect} differs from expected #{SUPPORTED_LOCK_VERSION}"
    )
  end

  root_name = lock_content.fetch("root", "root")
  nodes = lock_content.fetch("nodes", {})
  root_node = nodes.fetch(root_name, {})
  root_inputs = root_node.fetch("inputs", {})

  root_inputs.filter_map do |input_name, node_label|
    node = resolve_node(node_label, nodes)
    next unless node

    build_dependency(input_name, node)
  end
end