debian-mirror-gitlab/lib/gitlab/gitaly_client/remote_service.rb

89 lines
2.8 KiB
Ruby
Raw Normal View History

2019-02-15 15:39:39 +05:30
# frozen_string_literal: true
2018-03-17 18:26:18 +05:30
module Gitlab
module GitalyClient
class RemoteService
2018-11-20 20:47:30 +05:30
include Gitlab::EncodingHelper
2018-03-17 18:26:18 +05:30
MAX_MSG_SIZE = 128.kilobytes.freeze
2018-05-09 12:01:36 +05:30
def self.exists?(remote_url)
request = Gitaly::FindRemoteRepositoryRequest.new(remote: remote_url)
response = GitalyClient.call(GitalyClient.random_storage,
:remote_service,
:find_remote_repository, request,
timeout: GitalyClient.medium_timeout)
response.exists
end
2018-03-17 18:26:18 +05:30
def initialize(repository)
@repository = repository
@gitaly_repo = repository.gitaly_repository
@storage = repository.storage
end
def add_remote(name, url, mirror_refmaps)
request = Gitaly::AddRemoteRequest.new(
repository: @gitaly_repo,
name: name,
url: url,
mirror_refmaps: Array.wrap(mirror_refmaps).map(&:to_s)
)
2018-11-08 19:23:39 +05:30
GitalyClient.call(@storage, :remote_service, :add_remote, request, timeout: GitalyClient.fast_timeout)
2018-03-17 18:26:18 +05:30
end
def remove_remote(name)
request = Gitaly::RemoveRemoteRequest.new(repository: @gitaly_repo, name: name)
2019-12-21 20:55:43 +05:30
GitalyClient.call(@storage, :remote_service, :remove_remote, request, timeout: GitalyClient.long_timeout).result
2018-03-17 18:26:18 +05:30
end
2018-11-20 20:47:30 +05:30
def find_remote_root_ref(remote_name)
request = Gitaly::FindRemoteRootRefRequest.new(
repository: @gitaly_repo,
remote: remote_name
)
response = GitalyClient.call(@storage, :remote_service,
2019-12-21 20:55:43 +05:30
:find_remote_root_ref, request, timeout: GitalyClient.medium_timeout)
2018-11-20 20:47:30 +05:30
encode_utf8(response.ref)
end
2020-04-22 19:07:51 +05:30
def update_remote_mirror(ref_name, only_branches_matching, ssh_key: nil, known_hosts: nil, keep_divergent_refs: false)
2018-03-17 18:26:18 +05:30
req_enum = Enumerator.new do |y|
2019-02-15 15:39:39 +05:30
first_request = Gitaly::UpdateRemoteMirrorRequest.new(
2018-03-17 18:26:18 +05:30
repository: @gitaly_repo,
ref_name: ref_name
)
2019-02-15 15:39:39 +05:30
first_request.ssh_key = ssh_key if ssh_key.present?
first_request.known_hosts = known_hosts if known_hosts.present?
2020-04-22 19:07:51 +05:30
first_request.keep_divergent_refs = keep_divergent_refs
2019-02-15 15:39:39 +05:30
y.yield(first_request)
2018-03-17 18:26:18 +05:30
current_size = 0
slices = only_branches_matching.slice_before do |branch_name|
current_size += branch_name.bytesize
next false if current_size < MAX_MSG_SIZE
current_size = 0
end
slices.each do |slice|
y.yield Gitaly::UpdateRemoteMirrorRequest.new(only_branches_matching: slice)
end
end
2019-12-21 20:55:43 +05:30
GitalyClient.call(@storage, :remote_service, :update_remote_mirror, req_enum, timeout: GitalyClient.long_timeout)
2018-03-17 18:26:18 +05:30
end
end
end
end