2017-02-15 21:08:30 -05:00
|
|
|
module Gitlab
|
|
|
|
module GitalyClient
|
|
|
|
class Ref
|
|
|
|
attr_accessor :stub
|
|
|
|
|
|
|
|
def initialize(repository_storage, relative_path)
|
2017-04-06 10:54:15 -04:00
|
|
|
@channel = Util.channel(repository_storage)
|
|
|
|
@repository = Util.repository(repository_storage, relative_path)
|
2017-02-15 21:08:30 -05:00
|
|
|
@stub = Gitaly::Ref::Stub.new(nil, nil, channel_override: @channel)
|
|
|
|
end
|
|
|
|
|
|
|
|
def default_branch_name
|
|
|
|
request = Gitaly::FindDefaultBranchNameRequest.new(repository: @repository)
|
|
|
|
stub.find_default_branch_name(request).name.gsub(/^refs\/heads\//, '')
|
|
|
|
end
|
|
|
|
|
|
|
|
def branch_names
|
|
|
|
request = Gitaly::FindAllBranchNamesRequest.new(repository: @repository)
|
|
|
|
consume_refs_response(stub.find_all_branch_names(request), prefix: 'refs/heads/')
|
|
|
|
end
|
|
|
|
|
|
|
|
def tag_names
|
|
|
|
request = Gitaly::FindAllTagNamesRequest.new(repository: @repository)
|
|
|
|
consume_refs_response(stub.find_all_tag_names(request), prefix: 'refs/tags/')
|
|
|
|
end
|
|
|
|
|
2017-03-28 13:14:48 -04:00
|
|
|
def find_ref_name(commit_id, ref_prefix)
|
2017-04-06 12:47:35 -04:00
|
|
|
request = Gitaly::FindRefNameRequest.new(
|
2017-03-28 13:14:48 -04:00
|
|
|
repository: @repository,
|
|
|
|
commit_id: commit_id,
|
|
|
|
prefix: ref_prefix
|
|
|
|
)
|
|
|
|
|
|
|
|
stub.find_ref_name(request).name
|
|
|
|
end
|
|
|
|
|
2017-02-15 21:08:30 -05:00
|
|
|
private
|
|
|
|
|
|
|
|
def consume_refs_response(response, prefix:)
|
|
|
|
response.flat_map do |r|
|
|
|
|
r.names.map { |name| name.sub(/\A#{Regexp.escape(prefix)}/, '') }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|