Welcome to mirror list, hosted at ThFree Co, Russian Federation.

go_mod.rb « blob_viewer « models « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: eebf057c6dcbf3c4ee1f3b3a1d45e311fa202890 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# frozen_string_literal: true

module BlobViewer
  class GoMod < DependencyManager
    include ServerSide
    include Gitlab::Utils::StrongMemoize

    MODULE_REGEX = %r{
      \A (?# beginning of file)
      module\s+ (?# module directive)
      (?<name>.*?) (?# module name)
      \s*(?://.*)? (?# comment)
      (?:\n|\z) (?# newline or end of file)
    }x

    self.file_types = %i[go_mod go_sum]

    def manager_name
      'Go Modules'
    end

    def manager_url
      'https://golang.org/ref/mod'
    end

    def package_type
      'go'
    end

    def package_name
      strong_memoize(:package_name) do
        next if blob.name != 'go.mod'
        next unless match = MODULE_REGEX.match(blob.data)

        match[:name]
      end
    end

    def package_url
      Gitlab::Golang.package_url(package_name)
    end
  end
end