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

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-06-18 14:18:50 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-06-18 14:18:50 +0300
commit8c7f4e9d5f36cff46365a7f8c4b9c21578c1e781 (patch)
treea77e7fe7a93de11213032ed4ab1f33a3db51b738 /lib/gitlab/dependency_linker
parent00b35af3db1abfe813a778f643dad221aad51fca (diff)
Add latest changes from gitlab-org/gitlab@13-1-stable-ee
Diffstat (limited to 'lib/gitlab/dependency_linker')
-rw-r--r--lib/gitlab/dependency_linker/go_mod_linker.rb34
-rw-r--r--lib/gitlab/dependency_linker/go_sum_linker.rb38
2 files changed, 72 insertions, 0 deletions
diff --git a/lib/gitlab/dependency_linker/go_mod_linker.rb b/lib/gitlab/dependency_linker/go_mod_linker.rb
new file mode 100644
index 00000000000..4d6fe366333
--- /dev/null
+++ b/lib/gitlab/dependency_linker/go_mod_linker.rb
@@ -0,0 +1,34 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module DependencyLinker
+ class GoModLinker < BaseLinker
+ include Gitlab::Golang
+
+ self.file_type = :go_mod
+
+ private
+
+ SEMVER = Gitlab::Regex.unbounded_semver_regex
+ NAME = Gitlab::Regex.go_package_regex
+ REGEX = Regexp.new("(?<name>#{NAME.source})(?:\\s+(?<version>v#{SEMVER.source}))?", SEMVER.options | NAME.options).freeze
+
+ # rubocop: disable CodeReuse/ActiveRecord
+ def link_dependencies
+ highlighted_lines.map!.with_index do |rich_line, i|
+ plain_line = plain_lines[i].chomp
+ match = REGEX.match(plain_line)
+ next rich_line unless match
+
+ i, j = match.offset(:name)
+ marker = StringRangeMarker.new(plain_line, rich_line.html_safe)
+ marker.mark([i..(j - 1)]) do |text, left:, right:|
+ url = package_url(text, match[:version])
+ url ? link_tag(text, url) : text
+ end
+ end
+ end
+ # rubocop: enable CodeReuse/ActiveRecord
+ end
+ end
+end
diff --git a/lib/gitlab/dependency_linker/go_sum_linker.rb b/lib/gitlab/dependency_linker/go_sum_linker.rb
new file mode 100644
index 00000000000..20dc82ede9f
--- /dev/null
+++ b/lib/gitlab/dependency_linker/go_sum_linker.rb
@@ -0,0 +1,38 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module DependencyLinker
+ class GoSumLinker < GoModLinker
+ self.file_type = :go_sum
+
+ private
+
+ BASE64 = Gitlab::Regex.base64_regex
+ REGEX = Regexp.new("^\\s*(?<name>#{NAME.source})\\s+(?<version>v#{SEMVER.source})(\/go.mod)?\\s+h1:(?<checksum>#{BASE64.source})\\s*$", NAME.options).freeze
+
+ # rubocop: disable CodeReuse/ActiveRecord
+ def link_dependencies
+ highlighted_lines.map!.with_index do |rich_line, i|
+ plain_line = plain_lines[i].chomp
+ match = REGEX.match(plain_line)
+ next rich_line unless match
+
+ i0, j0 = match.offset(:name)
+ i2, j2 = match.offset(:checksum)
+
+ marker = StringRangeMarker.new(plain_line, rich_line.html_safe)
+ marker.mark([i0..(j0 - 1), i2..(j2 - 1)]) do |text, left:, right:|
+ if left
+ url = package_url(text, match[:version])
+ url ? link_tag(text, url) : text
+
+ elsif right
+ link_tag(text, "https://sum.golang.org/lookup/#{match[:name]}@#{match[:version]}")
+ end
+ end
+ end
+ end
+ # rubocop: enable CodeReuse/ActiveRecord
+ end
+ end
+end