Remove a dependency on gitlab-gollum-lib

Removing this dependency also allows us to remove a transitive
dependency on gitlab_grit - which is the whole point of this exercise.

I don't think we can EOL gitlab_grit until it's removed as a dependency
from gitaly-ruby, but this at least gets it out of gitlab-ce.
parent 27e9ed7a
......@@ -79,10 +79,6 @@ gem 'gpgme'
gem 'gitlab_omniauth-ldap', '~> 2.0.4', require: 'omniauth-ldap'
gem 'net-ldap'
# Git Wiki
# Only used to compute wiki page slugs
gem 'gitlab-gollum-lib', '~> 4.2', require: false
# API
gem 'grape', '~> 1.1'
gem 'grape-entity', '~> 0.7.1'
......
......@@ -278,19 +278,6 @@ GEM
google-protobuf (~> 3.1)
grpc (~> 1.10)
github-markup (1.7.0)
gitlab-gollum-lib (4.2.7.5)
gemojione (~> 3.2)
github-markup (~> 1.6)
gollum-grit_adapter (~> 1.0)
nokogiri (>= 1.6.1, < 2.0)
rouge (~> 3.1)
sanitize (~> 4.6.4)
stringex (~> 2.6)
gitlab-grit (2.8.2)
charlock_holmes (~> 0.6)
diff-lcs (~> 1.1)
mime-types (>= 1.16)
posix-spawn (~> 0.3)
gitlab-markup (1.6.4)
gitlab-sidekiq-fetcher (0.3.0)
sidekiq (~> 5)
......@@ -305,8 +292,6 @@ GEM
rubyntlm (~> 0.5)
globalid (0.4.1)
activesupport (>= 4.2.0)
gollum-grit_adapter (1.0.1)
gitlab-grit (~> 2.7, >= 2.7.1)
gon (6.2.0)
actionpack (>= 3.0)
multi_json
......@@ -596,7 +581,6 @@ GEM
pg (0.18.4)
po_to_json (1.0.1)
json (>= 1.6.0)
posix-spawn (0.3.13)
powerpack (0.1.1)
premailer (1.10.4)
addressable
......@@ -867,7 +851,6 @@ GEM
state_machines-activerecord (0.5.1)
activerecord (>= 4.1, < 6.0)
state_machines-activemodel (>= 0.5.0)
stringex (2.8.4)
sys-filesystem (1.1.6)
ffi
sysexits (1.2.0)
......@@ -1022,7 +1005,6 @@ DEPENDENCIES
gettext_i18n_rails_js (~> 1.3)
gitaly-proto (~> 0.118.1)
github-markup (~> 1.7.0)
gitlab-gollum-lib (~> 4.2)
gitlab-markup (~> 1.6.4)
gitlab-sidekiq-fetcher
gitlab-styles (~> 2.4)
......
......@@ -281,19 +281,6 @@ GEM
google-protobuf (~> 3.1)
grpc (~> 1.10)
github-markup (1.7.0)
gitlab-gollum-lib (4.2.7.5)
gemojione (~> 3.2)
github-markup (~> 1.6)
gollum-grit_adapter (~> 1.0)
nokogiri (>= 1.6.1, < 2.0)
rouge (~> 3.1)
sanitize (~> 4.6.4)
stringex (~> 2.6)
gitlab-grit (2.8.2)
charlock_holmes (~> 0.6)
diff-lcs (~> 1.1)
mime-types (>= 1.16)
posix-spawn (~> 0.3)
gitlab-markup (1.6.4)
gitlab-sidekiq-fetcher (0.3.0)
sidekiq (~> 5)
......@@ -308,8 +295,6 @@ GEM
rubyntlm (~> 0.5)
globalid (0.4.1)
activesupport (>= 4.2.0)
gollum-grit_adapter (1.0.1)
gitlab-grit (~> 2.7, >= 2.7.1)
gon (6.2.0)
actionpack (>= 3.0)
multi_json
......@@ -600,7 +585,6 @@ GEM
pg (0.18.4)
po_to_json (1.0.1)
json (>= 1.6.0)
posix-spawn (0.3.13)
powerpack (0.1.1)
premailer (1.10.4)
addressable
......@@ -875,7 +859,6 @@ GEM
state_machines-activerecord (0.5.1)
activerecord (>= 4.1, < 6.0)
state_machines-activemodel (>= 0.5.0)
stringex (2.8.4)
sys-filesystem (1.1.6)
ffi
sysexits (1.2.0)
......@@ -1031,7 +1014,6 @@ DEPENDENCIES
gettext_i18n_rails_js (~> 1.3)
gitaly-proto (~> 0.118.1)
github-markup (~> 1.7.0)
gitlab-gollum-lib (~> 4.2)
gitlab-markup (~> 1.6.4)
gitlab-sidekiq-fetcher
gitlab-styles (~> 2.4)
......
# We only need Gollum::Page so let's not load all of gollum-lib.
require 'gollum-lib/pagination'
require 'gollum-lib/wiki'
require 'gollum-lib/page'
module Gitlab
module Git
class Wiki
......@@ -18,6 +13,38 @@ module Gitlab
end
PageBlob = Struct.new(:name)
# GollumSlug inlines just enough knowledge from Gollum::Page to generate a
# slug, which is used when previewing pages that haven't been persisted
class GollumSlug
class << self
def format_to_ext(format)
format == :markdown ? 'md' : format.to_s
end
def cname(name, char_white_sub = '-', char_other_sub = '-')
if name.respond_to?(:gsub)
name.gsub(/\s/, char_white_sub).gsub(/[<>+]/, char_other_sub)
else
''
end
end
def generate(title, format)
name = cname(title) + '.' + format_to_ext(format)
blob = PageBlob.new(name)
path =
if blob.name.include?('/')
blob.name.sub(%r{/[^/]+$}, '/')
else
''
end
path + cname(name)
end
end
end
attr_reader :repository
def self.default_ref
......@@ -90,15 +117,7 @@ module Gitlab
end
def preview_slug(title, format)
# Adapted from gollum gem (Gollum::Wiki#preview_page) to avoid
# using Rugged through a Gollum::Wiki instance
page_class = Gollum::Page
page = page_class.new(nil)
ext = page_class.format_to_ext(format.to_sym)
name = page_class.cname(title) + '.' + ext
blob = PageBlob.new(name)
page.populate(blob)
page.url_path
GollumSlug.generate(title, format)
end
def page_formatted_data(title:, dir: nil, version: nil)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment