gitlab-org--gitlab-foss/lib/gitlab/dependency_linker/gemfile_linker.rb

35 lines
971 B
Ruby
Raw Normal View History

# frozen_string_literal: true
2016-07-10 21:13:06 +00:00
module Gitlab
module DependencyLinker
2017-05-16 20:25:57 +00:00
class GemfileLinker < MethodLinker
self.file_type = :gemfile
2016-07-10 21:13:06 +00:00
private
def link_dependencies
2017-05-16 20:25:57 +00:00
link_urls
link_packages
end
2016-07-10 21:13:06 +00:00
2017-05-16 20:25:57 +00:00
def link_urls
2016-07-10 21:13:06 +00:00
# Link `github: "user/repo"` to https://github.com/user/repo
2017-05-16 20:25:57 +00:00
link_regex(/(github:|:github\s*=>)\s*['"](?<name>[^'"]+)['"]/, &method(:github_url))
2016-07-10 21:13:06 +00:00
2017-05-12 15:29:25 +00:00
# Link `git: "https://gitlab.example.com/user/repo"` to https://gitlab.example.com/user/repo
2018-01-27 05:35:53 +00:00
link_regex(/(git:|:git\s*=>)\s*['"](?<name>#{URL_REGEX})['"]/, &:itself)
2017-05-12 15:29:25 +00:00
2016-07-10 21:13:06 +00:00
# Link `source "https://rubygems.org"` to https://rubygems.org
2017-05-16 20:25:57 +00:00
link_method_call('source', URL_REGEX, &:itself)
2016-07-10 21:13:06 +00:00
end
2017-05-16 20:25:57 +00:00
def link_packages
# Link `gem "package_name"` to https://rubygems.org/gems/package_name
link_method_call('gem') do |name|
"https://rubygems.org/gems/#{name}"
end
2016-07-10 21:13:06 +00:00
end
end
end
end