diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-06-10 12:08:35 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-06-10 12:08:35 +0300 |
commit | 23ff717a29540bb1d4b0068f164b5f9df99386bf (patch) | |
tree | 1d31f1766f3a5e4748cd806cf655d72d35cb59dc /app/models/blob_viewer | |
parent | c2879da99d02b4e49a1394f5699a2963f2651f18 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/models/blob_viewer')
-rw-r--r-- | app/models/blob_viewer/go_mod.rb | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/app/models/blob_viewer/go_mod.rb b/app/models/blob_viewer/go_mod.rb new file mode 100644 index 00000000000..ae57e2c0526 --- /dev/null +++ b/app/models/blob_viewer/go_mod.rb @@ -0,0 +1,43 @@ +# frozen_string_literal: true + +module BlobViewer + class GoMod < DependencyManager + include ServerSide + include Gitlab::Utils::StrongMemoize + + MODULE_REGEX = / + \A (?# beginning of file) + module\s+ (?# module directive) + (?<name>.*?) (?# module name) + \s*(?:\/\/.*)? (?# comment) + (?:\n|\z) (?# newline or end of file) + /x.freeze + + 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 |