Use ProjectWiki instead of GollumWiki in code
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
This commit is contained in:
parent
26ec74c446
commit
1bd28994cc
|
@ -1,120 +0,0 @@
|
|||
class GollumWiki
|
||||
include Gitlab::ShellAdapter
|
||||
|
||||
MARKUPS = {
|
||||
"Markdown" => :markdown,
|
||||
"RDoc" => :rdoc
|
||||
}
|
||||
|
||||
class CouldNotCreateWikiError < StandardError; end
|
||||
|
||||
# Returns a string describing what went wrong after
|
||||
# an operation fails.
|
||||
attr_reader :error_message
|
||||
|
||||
def initialize(project, user = nil)
|
||||
@project = project
|
||||
@user = user
|
||||
end
|
||||
|
||||
def path
|
||||
@project.path + '.wiki'
|
||||
end
|
||||
|
||||
def path_with_namespace
|
||||
@project.path_with_namespace + ".wiki"
|
||||
end
|
||||
|
||||
def url_to_repo
|
||||
gitlab_shell.url_to_repo(path_with_namespace)
|
||||
end
|
||||
|
||||
def ssh_url_to_repo
|
||||
url_to_repo
|
||||
end
|
||||
|
||||
def http_url_to_repo
|
||||
[Gitlab.config.gitlab.url, "/", path_with_namespace, ".git"].join('')
|
||||
end
|
||||
|
||||
# Returns the Gollum::Wiki object.
|
||||
def wiki
|
||||
@wiki ||= begin
|
||||
Gollum::Wiki.new(path_to_repo)
|
||||
rescue Gollum::NoSuchPathError
|
||||
create_repo!
|
||||
end
|
||||
end
|
||||
|
||||
def empty?
|
||||
pages.empty?
|
||||
end
|
||||
|
||||
# Returns an Array of Gitlab WikiPage instances or an
|
||||
# empty Array if this Wiki has no pages.
|
||||
def pages
|
||||
wiki.pages.map { |page| WikiPage.new(self, page, true) }
|
||||
end
|
||||
|
||||
# Finds a page within the repository based on a tile
|
||||
# or slug.
|
||||
#
|
||||
# title - The human readable or parameterized title of
|
||||
# the page.
|
||||
#
|
||||
# Returns an initialized WikiPage instance or nil
|
||||
def find_page(title, version = nil)
|
||||
if page = wiki.page(title, version)
|
||||
WikiPage.new(self, page, true)
|
||||
else
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
def create_page(title, content, format = :markdown, message = nil)
|
||||
commit = commit_details(:created, message, title)
|
||||
|
||||
wiki.write_page(title, format, content, commit)
|
||||
rescue Gollum::DuplicatePageError => e
|
||||
@error_message = "Duplicate page: #{e.message}"
|
||||
return false
|
||||
end
|
||||
|
||||
def update_page(page, content, format = :markdown, message = nil)
|
||||
commit = commit_details(:updated, message, page.title)
|
||||
|
||||
wiki.update_page(page, page.name, format, content, commit)
|
||||
end
|
||||
|
||||
def delete_page(page, message = nil)
|
||||
wiki.delete_page(page, commit_details(:deleted, message, page.title))
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def create_repo!
|
||||
if init_repo(path_with_namespace)
|
||||
Gollum::Wiki.new(path_to_repo)
|
||||
else
|
||||
raise CouldNotCreateWikiError
|
||||
end
|
||||
end
|
||||
|
||||
def init_repo(path_with_namespace)
|
||||
gitlab_shell.add_repository(path_with_namespace)
|
||||
end
|
||||
|
||||
def commit_details(action, message = nil, title = nil)
|
||||
commit_message = message || default_message(action, title)
|
||||
|
||||
{email: @user.email, name: @user.name, message: commit_message}
|
||||
end
|
||||
|
||||
def default_message(action, title)
|
||||
"#{@user.username} #{action} page: #{title}"
|
||||
end
|
||||
|
||||
def path_to_repo
|
||||
@path_to_repo ||= File.join(Gitlab.config.gitlab_shell.repos_path, "#{path_with_namespace}.git")
|
||||
end
|
||||
end
|
|
@ -74,8 +74,8 @@ module Projects
|
|||
if @project.wiki_enabled?
|
||||
begin
|
||||
# force the creation of a wiki,
|
||||
GollumWiki.new(@project, @project.owner).wiki
|
||||
rescue GollumWiki::CouldNotCreateWikiError => ex
|
||||
ProjectWiki.new(@project, @project.owner).wiki
|
||||
rescue ProjectWiki::CouldNotCreateWikiError => ex
|
||||
# Prevent project observer crash
|
||||
# if failed to create wiki
|
||||
nil
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
class ProjectWiki < Spinach::FeatureSteps
|
||||
class Spinach::Features::ProjectWiki < Spinach::FeatureSteps
|
||||
include SharedAuthentication
|
||||
include SharedProject
|
||||
include SharedNote
|
||||
|
@ -16,7 +16,7 @@ class ProjectWiki < Spinach::FeatureSteps
|
|||
end
|
||||
|
||||
Given 'I create the Wiki Home page' do
|
||||
fill_in "Content", with: '[link test](test)'
|
||||
fill_in "wiki_content", with: '[link test](test)'
|
||||
click_on "Create page"
|
||||
end
|
||||
|
||||
|
@ -87,6 +87,6 @@ class ProjectWiki < Spinach::FeatureSteps
|
|||
end
|
||||
|
||||
def wiki
|
||||
@gollum_wiki = GollumWiki.new(project, current_user)
|
||||
@project_wiki = ProjectWiki.new(project, current_user)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -24,7 +24,7 @@ module Backup
|
|||
puts "[FAILED]".red
|
||||
end
|
||||
|
||||
wiki = GollumWiki.new(project)
|
||||
wiki = ProjectWiki.new(project)
|
||||
|
||||
if File.exists?(path_to_repo(wiki))
|
||||
print " * #{wiki.path_with_namespace} ... "
|
||||
|
@ -59,7 +59,7 @@ module Backup
|
|||
puts "[FAILED]".red
|
||||
end
|
||||
|
||||
wiki = GollumWiki.new(project)
|
||||
wiki = ProjectWiki.new(project)
|
||||
|
||||
if File.exists?(path_to_bundle(wiki))
|
||||
print " * #{wiki.path_with_namespace} ... "
|
||||
|
|
|
@ -60,6 +60,8 @@ class Redcarpet::Render::GitlabHTML < Redcarpet::Render::HTML
|
|||
end
|
||||
|
||||
def is_wiki?
|
||||
@template.instance_variable_get("@wiki")
|
||||
if @template.instance_variable_get("@project_wiki")
|
||||
@template.instance_variable_get("@page")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
require "spec_helper"
|
||||
|
||||
describe GollumWiki do
|
||||
describe ProjectWiki do
|
||||
|
||||
def remove_temp_repo(path)
|
||||
FileUtils.rm_rf path
|
||||
|
@ -23,7 +23,7 @@ describe GollumWiki do
|
|||
let(:user) { project.owner }
|
||||
let(:gitlab_shell) { Gitlab::Shell.new }
|
||||
|
||||
subject { GollumWiki.new(project, user) }
|
||||
subject { ProjectWiki.new(project, user) }
|
||||
|
||||
before do
|
||||
create_temp_repo(subject.send(:path_to_repo))
|
||||
|
@ -68,15 +68,15 @@ describe GollumWiki do
|
|||
end
|
||||
|
||||
it "creates a new wiki repo if one does not yet exist" do
|
||||
wiki = GollumWiki.new(project, user)
|
||||
wiki = ProjectWiki.new(project, user)
|
||||
wiki.create_page("index", "test content").should_not == false
|
||||
|
||||
FileUtils.rm_rf wiki.send(:path_to_repo)
|
||||
end
|
||||
|
||||
it "raises CouldNotCreateWikiError if it can't create the wiki repository" do
|
||||
GollumWiki.any_instance.stub(:init_repo).and_return(false)
|
||||
expect { GollumWiki.new(project, user).wiki }.to raise_exception(GollumWiki::CouldNotCreateWikiError)
|
||||
ProjectWiki.any_instance.stub(:init_repo).and_return(false)
|
||||
expect { ProjectWiki.new(project, user).wiki }.to raise_exception(ProjectWiki::CouldNotCreateWikiError)
|
||||
end
|
||||
end
|
||||
|
|
@ -22,7 +22,7 @@ describe WikiPage do
|
|||
let(:project) { create(:project) }
|
||||
let(:repository) { project.repository }
|
||||
let(:user) { project.owner }
|
||||
let(:wiki) { GollumWiki.new(project, user) }
|
||||
let(:wiki) { ProjectWiki.new(project, user) }
|
||||
|
||||
subject { WikiPage.new(wiki) }
|
||||
|
||||
|
|
|
@ -42,7 +42,7 @@ describe Projects::CreateService do
|
|||
context 'wiki_enabled true creates wiki repository directory' do
|
||||
before do
|
||||
@project = create_project(@user, @opts)
|
||||
@path = GollumWiki.new(@project, @user).send(:path_to_repo)
|
||||
@path = ProjectWiki.new(@project, @user).send(:path_to_repo)
|
||||
end
|
||||
|
||||
it { File.exists?(@path).should be_true }
|
||||
|
@ -52,7 +52,7 @@ describe Projects::CreateService do
|
|||
before do
|
||||
@opts.merge!(wiki_enabled: false)
|
||||
@project = create_project(@user, @opts)
|
||||
@path = GollumWiki.new(@project, @user).send(:path_to_repo)
|
||||
@path = ProjectWiki.new(@project, @user).send(:path_to_repo)
|
||||
end
|
||||
|
||||
it { File.exists?(@path).should be_false }
|
||||
|
|
|
@ -52,7 +52,7 @@ module TestEnv
|
|||
def setup_stubs()
|
||||
# Use tmp dir for FS manipulations
|
||||
repos_path = testing_path()
|
||||
GollumWiki.any_instance.stub(:init_repo) do |path|
|
||||
ProjectWiki.any_instance.stub(:init_repo) do |path|
|
||||
create_temp_repo(File.join(repos_path, "#{path}.git"))
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue