debian-mirror-gitlab/lib/gitlab/hook_data/base_builder.rb

52 lines
1.1 KiB
Ruby
Raw Normal View History

2019-02-15 15:39:39 +05:30
# frozen_string_literal: true
2018-11-18 11:00:15 +05:30
module Gitlab
module HookData
class BaseBuilder
attr_accessor :object
MARKDOWN_SIMPLE_IMAGE = %r{
#{::Gitlab::Regex.markdown_code_or_html_blocks}
|
(?<image>
!
\[(?<title>[^\n]*?)\]
\((?<url>(?!(https?://|//))[^\n]+?)\)
)
}mx.freeze
def initialize(object)
@object = object
end
private
def absolute_image_urls(markdown_text)
return markdown_text unless markdown_text.present?
markdown_text.gsub(MARKDOWN_SIMPLE_IMAGE) do
if $~[:image]
url = $~[:url]
2018-12-13 13:39:08 +05:30
url = "#{uploads_prefix}#{url}" if url.start_with?('/uploads')
2018-11-18 11:00:15 +05:30
url = "/#{url}" unless url.start_with?('/')
"![#{$~[:title]}](#{Gitlab.config.gitlab.url}#{url})"
else
$~[0]
end
end
end
2018-12-13 13:39:08 +05:30
def uploads_prefix
project&.full_path || ''
end
def project
return unless object.respond_to?(:project)
object.project
end
2018-11-18 11:00:15 +05:30
end
end
end