Commit 377c10b4 authored by Robert Speicher's avatar Robert Speicher

Merge branch 'feature/migrate-workhorse-send-git-diff-patch-to-gitaly' into 'master'

Migrate Workhorse Send{Diff,Patch} to Gitaly

See merge request gitlab-org/gitlab-ce!14652
parents 100a7c6b 618dd9e4
...@@ -103,11 +103,16 @@ module Gitlab ...@@ -103,11 +103,16 @@ module Gitlab
end end
def send_git_diff(repository, diff_refs) def send_git_diff(repository, diff_refs)
params = { params = if Gitlab::GitalyClient.feature_enabled?(:workhorse_send_git_diff)
'RepoPath' => repository.path_to_repo, {
'ShaFrom' => diff_refs.base_sha, 'GitalyServer' => gitaly_server_hash(repository),
'ShaTo' => diff_refs.head_sha 'RawDiffRequest' => Gitaly::RawDiffRequest.new(
gitaly_diff_or_patch_hash(repository, diff_refs)
).to_json
} }
else
workhorse_diff_or_patch_hash(repository, diff_refs)
end
[ [
SEND_DATA_HEADER, SEND_DATA_HEADER,
...@@ -116,11 +121,16 @@ module Gitlab ...@@ -116,11 +121,16 @@ module Gitlab
end end
def send_git_patch(repository, diff_refs) def send_git_patch(repository, diff_refs)
params = { params = if Gitlab::GitalyClient.feature_enabled?(:workhorse_send_git_patch)
'RepoPath' => repository.path_to_repo, {
'ShaFrom' => diff_refs.base_sha, 'GitalyServer' => gitaly_server_hash(repository),
'ShaTo' => diff_refs.head_sha 'RawPatchRequest' => Gitaly::RawPatchRequest.new(
gitaly_diff_or_patch_hash(repository, diff_refs)
).to_json
} }
else
workhorse_diff_or_patch_hash(repository, diff_refs)
end
[ [
SEND_DATA_HEADER, SEND_DATA_HEADER,
...@@ -216,6 +226,22 @@ module Gitlab ...@@ -216,6 +226,22 @@ module Gitlab
token: Gitlab::GitalyClient.token(repository.project.repository_storage) token: Gitlab::GitalyClient.token(repository.project.repository_storage)
} }
end end
def workhorse_diff_or_patch_hash(repository, diff_refs)
{
'RepoPath' => repository.path_to_repo,
'ShaFrom' => diff_refs.base_sha,
'ShaTo' => diff_refs.head_sha
}
end
def gitaly_diff_or_patch_hash(repository, diff_refs)
{
repository: repository.gitaly_repository,
left_commit_id: diff_refs.base_sha,
right_commit_id: diff_refs.head_sha
}
end
end end
end end
end end
...@@ -66,6 +66,27 @@ describe Gitlab::Workhorse do ...@@ -66,6 +66,27 @@ describe Gitlab::Workhorse do
let(:diff_refs) { double(base_sha: "base", head_sha: "head") } let(:diff_refs) { double(base_sha: "base", head_sha: "head") }
subject { described_class.send_git_patch(repository, diff_refs) } subject { described_class.send_git_patch(repository, diff_refs) }
context 'when Gitaly workhorse_send_git_patch feature is enabled' do
it 'sets the header correctly' do
key, command, params = decode_workhorse_header(subject)
expect(key).to eq("Gitlab-Workhorse-Send-Data")
expect(command).to eq("git-format-patch")
expect(params).to eq({
'GitalyServer' => {
address: Gitlab::GitalyClient.address(project.repository_storage),
token: Gitlab::GitalyClient.token(project.repository_storage)
},
'RawPatchRequest' => Gitaly::RawPatchRequest.new(
repository: repository.gitaly_repository,
left_commit_id: 'base',
right_commit_id: 'head'
).to_json
}.deep_stringify_keys)
end
end
context 'when Gitaly workhorse_send_git_patch feature is disabled', skip_gitaly_mock: true do
it 'sets the header correctly' do it 'sets the header correctly' do
key, command, params = decode_workhorse_header(subject) key, command, params = decode_workhorse_header(subject)
...@@ -74,6 +95,7 @@ describe Gitlab::Workhorse do ...@@ -74,6 +95,7 @@ describe Gitlab::Workhorse do
expect(params).to eq("RepoPath" => repository.path_to_repo, "ShaFrom" => "base", "ShaTo" => "head") expect(params).to eq("RepoPath" => repository.path_to_repo, "ShaFrom" => "base", "ShaTo" => "head")
end end
end end
end
describe '.terminal_websocket' do describe '.terminal_websocket' do
def terminal(ca_pem: nil) def terminal(ca_pem: nil)
...@@ -115,16 +137,38 @@ describe Gitlab::Workhorse do ...@@ -115,16 +137,38 @@ describe Gitlab::Workhorse do
describe '.send_git_diff' do describe '.send_git_diff' do
let(:diff_refs) { double(base_sha: "base", head_sha: "head") } let(:diff_refs) { double(base_sha: "base", head_sha: "head") }
subject { described_class.send_git_patch(repository, diff_refs) } subject { described_class.send_git_diff(repository, diff_refs) }
context 'when Gitaly workhorse_send_git_diff feature is enabled' do
it 'sets the header correctly' do it 'sets the header correctly' do
key, command, params = decode_workhorse_header(subject) key, command, params = decode_workhorse_header(subject)
expect(key).to eq("Gitlab-Workhorse-Send-Data") expect(key).to eq("Gitlab-Workhorse-Send-Data")
expect(command).to eq("git-format-patch") expect(command).to eq("git-diff")
expect(params).to eq({
'GitalyServer' => {
address: Gitlab::GitalyClient.address(project.repository_storage),
token: Gitlab::GitalyClient.token(project.repository_storage)
},
'RawDiffRequest' => Gitaly::RawDiffRequest.new(
repository: repository.gitaly_repository,
left_commit_id: 'base',
right_commit_id: 'head'
).to_json
}.deep_stringify_keys)
end
end
context 'when Gitaly workhorse_send_git_diff feature is disabled', skip_gitaly_mock: true do
it 'sets the header correctly' do
key, command, params = decode_workhorse_header(subject)
expect(key).to eq("Gitlab-Workhorse-Send-Data")
expect(command).to eq("git-diff")
expect(params).to eq("RepoPath" => repository.path_to_repo, "ShaFrom" => "base", "ShaTo" => "head") expect(params).to eq("RepoPath" => repository.path_to_repo, "ShaFrom" => "base", "ShaTo" => "head")
end end
end end
end
describe ".secret" do describe ".secret" do
subject { described_class.secret } subject { described_class.secret }
......
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