Commit b3a01662 authored by Ahmad Sherif's avatar Ahmad Sherif

Migrate Gitlab::Git::Wiki#delete_page to Gitaly

Closes gitaly#673
parent 7e78db6e
...@@ -398,7 +398,7 @@ group :ed25519 do ...@@ -398,7 +398,7 @@ group :ed25519 do
end end
# Gitaly GRPC client # Gitaly GRPC client
gem 'gitaly-proto', '~> 0.48.0', require: 'gitaly' gem 'gitaly-proto', '~> 0.51.0', require: 'gitaly'
gem 'toml-rb', '~> 0.3.15', require: false gem 'toml-rb', '~> 0.3.15', require: false
......
...@@ -273,7 +273,7 @@ GEM ...@@ -273,7 +273,7 @@ GEM
po_to_json (>= 1.0.0) po_to_json (>= 1.0.0)
rails (>= 3.2.0) rails (>= 3.2.0)
gherkin-ruby (0.3.2) gherkin-ruby (0.3.2)
gitaly-proto (0.48.0) gitaly-proto (0.51.0)
google-protobuf (~> 3.1) google-protobuf (~> 3.1)
grpc (~> 1.0) grpc (~> 1.0)
github-linguist (4.7.6) github-linguist (4.7.6)
...@@ -1030,7 +1030,7 @@ DEPENDENCIES ...@@ -1030,7 +1030,7 @@ DEPENDENCIES
gettext (~> 3.2.2) gettext (~> 3.2.2)
gettext_i18n_rails (~> 1.8.0) gettext_i18n_rails (~> 1.8.0)
gettext_i18n_rails_js (~> 1.2.0) gettext_i18n_rails_js (~> 1.2.0)
gitaly-proto (~> 0.48.0) gitaly-proto (~> 0.51.0)
github-linguist (~> 4.7.0) github-linguist (~> 4.7.0)
gitlab-flowdock-git-hook (~> 1.0.1) gitlab-flowdock-git-hook (~> 1.0.1)
gitlab-markup (~> 1.6.2) gitlab-markup (~> 1.6.2)
......
...@@ -35,10 +35,14 @@ module Gitlab ...@@ -35,10 +35,14 @@ module Gitlab
end end
def delete_page(page_path, commit_details) def delete_page(page_path, commit_details)
assert_type!(commit_details, CommitDetails) @repository.gitaly_migrate(:wiki_delete_page) do |is_enabled|
if is_enabled
gollum_wiki.delete_page(gollum_page_by_path(page_path), commit_details.to_h) gitaly_delete_page(page_path, commit_details)
nil gollum_wiki.clear_cache
else
gollum_delete_page(page_path, commit_details)
end
end
end end
def update_page(page_path, title, format, content, commit_details) def update_page(page_path, title, format, content, commit_details)
...@@ -135,9 +139,20 @@ module Gitlab ...@@ -135,9 +139,20 @@ module Gitlab
raise Gitlab::Git::Wiki::DuplicatePageError, e.message raise Gitlab::Git::Wiki::DuplicatePageError, e.message
end end
def gollum_delete_page(page_path, commit_details)
assert_type!(commit_details, CommitDetails)
gollum_wiki.delete_page(gollum_page_by_path(page_path), commit_details.to_h)
nil
end
def gitaly_write_page(name, format, content, commit_details) def gitaly_write_page(name, format, content, commit_details)
gitaly_wiki_client.write_page(name, format, content, commit_details) gitaly_wiki_client.write_page(name, format, content, commit_details)
end end
def gitaly_delete_page(page_path, commit_details)
gitaly_wiki_client.delete_page(page_path, commit_details)
end
end end
end end
end end
...@@ -15,11 +15,7 @@ module Gitlab ...@@ -15,11 +15,7 @@ module Gitlab
repository: @gitaly_repo, repository: @gitaly_repo,
name: GitalyClient.encode(name), name: GitalyClient.encode(name),
format: format.to_s, format: format.to_s,
commit_details: Gitaly::WikiCommitDetails.new( commit_details: gitaly_commit_details(commit_details)
name: GitalyClient.encode(commit_details.name),
email: GitalyClient.encode(commit_details.email),
message: GitalyClient.encode(commit_details.message)
)
) )
strio = StringIO.new(content) strio = StringIO.new(content)
...@@ -40,6 +36,26 @@ module Gitlab ...@@ -40,6 +36,26 @@ module Gitlab
raise Gitlab::Git::Wiki::DuplicatePageError, error raise Gitlab::Git::Wiki::DuplicatePageError, error
end end
end end
def delete_page(page_path, commit_details)
request = Gitaly::WikiDeletePageRequest.new(
repository: @gitaly_repo,
page_path: GitalyClient.encode(page_path),
commit_details: gitaly_commit_details(commit_details)
)
GitalyClient.call(@repository.storage, :wiki_service, :wiki_delete_page, request)
end
private
def gitaly_commit_details(commit_details)
Gitaly::WikiCommitDetails.new(
name: GitalyClient.encode(commit_details.name),
email: GitalyClient.encode(commit_details.email),
message: GitalyClient.encode(commit_details.message)
)
end
end end
end end
end end
...@@ -265,23 +265,33 @@ describe ProjectWiki do ...@@ -265,23 +265,33 @@ describe ProjectWiki do
end end
describe "#delete_page" do describe "#delete_page" do
before do shared_examples 'deleting a wiki page' do
create_page("index", "some content") before do
@page = subject.wiki.page(title: "index") create_page("index", "some content")
end @page = subject.wiki.page(title: "index")
end
it "deletes the page" do it "deletes the page" do
subject.delete_page(@page) subject.delete_page(@page)
expect(subject.pages.count).to eq(0) expect(subject.pages.count).to eq(0)
end end
it 'updates project activity' do it 'updates project activity' do
subject.delete_page(@page) subject.delete_page(@page)
project.reload project.reload
expect(project.last_activity_at).to be_within(1.minute).of(Time.now) expect(project.last_activity_at).to be_within(1.minute).of(Time.now)
expect(project.last_repository_updated_at).to be_within(1.minute).of(Time.now) expect(project.last_repository_updated_at).to be_within(1.minute).of(Time.now)
end
end
context 'when Gitaly wiki_delete_page is enabled' do
it_behaves_like 'deleting a wiki page'
end
context 'when Gitaly wiki_delete_page is disabled', :skip_gitaly_mock do
it_behaves_like 'deleting a wiki page'
end end
end end
...@@ -343,6 +353,6 @@ describe ProjectWiki do ...@@ -343,6 +353,6 @@ describe ProjectWiki do
end end
def destroy_page(page) def destroy_page(page)
subject.delete_page(page, commit_details) subject.delete_page(page, "test commit")
end end
end end
...@@ -402,7 +402,7 @@ describe WikiPage do ...@@ -402,7 +402,7 @@ describe WikiPage do
def destroy_page(title) def destroy_page(title)
page = wiki.wiki.page(title: title) page = wiki.wiki.page(title: title)
wiki.delete_page(page, commit_details) wiki.delete_page(page, "test commit")
end end
def get_slugs(page_or_dir) def get_slugs(page_or_dir)
......
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