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>2019-12-18 15:07:48 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2019-12-18 15:07:48 +0300
commit79d62647bcfad69d7272020acb7d8be5ee5df003 (patch)
tree008d96a4c5fdfdecda79dae5e942c7df07511c77 /lib/gitlab/dependency_linker
parent1a9d9cc14ec54036548824e3ce17da03960f5f81 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/gitlab/dependency_linker')
-rw-r--r--lib/gitlab/dependency_linker/cargo_toml_linker.rb46
1 files changed, 46 insertions, 0 deletions
diff --git a/lib/gitlab/dependency_linker/cargo_toml_linker.rb b/lib/gitlab/dependency_linker/cargo_toml_linker.rb
new file mode 100644
index 00000000000..57e0a5f4699
--- /dev/null
+++ b/lib/gitlab/dependency_linker/cargo_toml_linker.rb
@@ -0,0 +1,46 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module DependencyLinker
+ class CargoTomlLinker < BaseLinker
+ self.file_type = :cargo_toml
+
+ def link
+ return highlighted_text unless toml
+
+ super
+ end
+
+ private
+
+ def link_dependencies
+ link_dependencies_at("dependencies")
+ link_dependencies_at("dev-dependencies")
+ link_dependencies_at("build-dependencies")
+ end
+
+ def link_dependencies_at(type)
+ dependencies = toml[type]
+ return unless dependencies
+
+ dependencies.each do |name, value|
+ link_toml(name, value, type) do |name|
+ "https://crates.io/crates/#{name}"
+ end
+ end
+ end
+
+ def link_toml(key, value, type, &url_proc)
+ if value.is_a? String
+ link_regex(/^(?<name>#{key})\s*=\s*"#{value}"/, &url_proc)
+ else
+ link_regex(/^\[#{type}\.(?<name>#{key})]/, &url_proc)
+ end
+ end
+
+ def toml
+ @toml ||= TomlRB.parse(plain_text) rescue nil
+ end
+ end
+ end
+end