Class: Dependabot::GoModules::FileParser

Inherits:
FileParsers::Base
  • Object
show all
Defined in:
lib/dependabot/go_modules/file_parser.rb

Constant Summary collapse

GIT_VERSION_REGEX =
/^v\d+\.\d+\.\d+-.*-(?<sha>[0-9a-f]{12})$/.freeze

Instance Method Summary collapse

Instance Method Details

#parseObject


16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/dependabot/go_modules/file_parser.rb', line 16

def parse
  dependency_set = Dependabot::FileParsers::Base::DependencySet.new

  i = 0
  chunks = module_info.lines.
           group_by { |line| line == "{\n" ? i += 1 : i }
  deps = chunks.values.map { |chunk| JSON.parse(chunk.join) }

  deps.each do |dep|
    # The project itself appears in this list as "Main"
    next if dep["Main"]

    dependency = dependency_from_details(dep)
    dependency_set << dependency if dependency
  end

  dependency_set.dependencies
end