Migrate Workhorse Send{Diff,Patch} to Gitaly
This commit is contained in:
parent
1c0407e84c
commit
618dd9e4b2
|
@ -1 +1 @@
|
|||
0.43.0
|
||||
0.44.0
|
||||
|
|
|
@ -103,11 +103,16 @@ module Gitlab
|
|||
end
|
||||
|
||||
def send_git_diff(repository, diff_refs)
|
||||
params = {
|
||||
'RepoPath' => repository.path_to_repo,
|
||||
'ShaFrom' => diff_refs.base_sha,
|
||||
'ShaTo' => diff_refs.head_sha
|
||||
params = if Gitlab::GitalyClient.feature_enabled?(:workhorse_send_git_diff)
|
||||
{
|
||||
'GitalyServer' => gitaly_server_hash(repository),
|
||||
'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,
|
||||
|
@ -116,11 +121,16 @@ module Gitlab
|
|||
end
|
||||
|
||||
def send_git_patch(repository, diff_refs)
|
||||
params = {
|
||||
'RepoPath' => repository.path_to_repo,
|
||||
'ShaFrom' => diff_refs.base_sha,
|
||||
'ShaTo' => diff_refs.head_sha
|
||||
params = if Gitlab::GitalyClient.feature_enabled?(:workhorse_send_git_patch)
|
||||
{
|
||||
'GitalyServer' => gitaly_server_hash(repository),
|
||||
'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,
|
||||
|
@ -216,6 +226,22 @@ module Gitlab
|
|||
token: Gitlab::GitalyClient.token(repository.project.repository_storage)
|
||||
}
|
||||
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
|
||||
|
|
|
@ -66,6 +66,27 @@ describe Gitlab::Workhorse do
|
|||
let(:diff_refs) { double(base_sha: "base", head_sha: "head") }
|
||||
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
|
||||
key, command, params = decode_workhorse_header(subject)
|
||||
|
||||
|
@ -74,6 +95,7 @@ describe Gitlab::Workhorse do
|
|||
expect(params).to eq("RepoPath" => repository.path_to_repo, "ShaFrom" => "base", "ShaTo" => "head")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '.terminal_websocket' do
|
||||
def terminal(ca_pem: nil)
|
||||
|
@ -115,16 +137,38 @@ describe Gitlab::Workhorse do
|
|||
|
||||
describe '.send_git_diff' do
|
||||
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
|
||||
key, command, params = decode_workhorse_header(subject)
|
||||
|
||||
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")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe ".secret" do
|
||||
subject { described_class.secret }
|
||||
|
|
Loading…
Reference in New Issue