Commit 113a479a authored by Douglas Barbosa Alexandre's avatar Douglas Barbosa Alexandre

Merge branch 'list-refs-bindings' into 'master'

Add ListRefs bindings

See merge request gitlab-org/gitlab!72518
parents 0b48a8a8 65a4b948
......@@ -784,6 +784,12 @@ module Gitlab
end
end
def list_refs
wrapped_gitaly_errors do
gitaly_ref_client.list_refs
end
end
# Refactoring aid; allows us to copy code from app/models/repository.rb
def commit(ref = 'HEAD')
Gitlab::Git::Commit.find(self, ref)
......
......@@ -194,6 +194,16 @@ module Gitlab
raise ArgumentError, ex
end
def list_refs(patterns = [Gitlab::Git::BRANCH_REF_PREFIX])
request = Gitaly::ListRefsRequest.new(
repository: @gitaly_repo,
patterns: patterns
)
response = GitalyClient.call(@storage, :ref_service, :list_refs, request, timeout: GitalyClient.fast_timeout)
consume_list_refs_response(response)
end
def pack_refs
request = Gitaly::PackRefsRequest.new(repository: @gitaly_repo)
......@@ -206,6 +216,10 @@ module Gitlab
response.flat_map { |message| message.names.map { |name| yield(name) } }
end
def consume_list_refs_response(response)
response.flat_map(&:references)
end
def sort_local_branches_by_param(sort_by)
sort_by = 'name' if sort_by == 'name_asc'
......
......@@ -1888,6 +1888,18 @@ RSpec.describe Gitlab::Git::Repository, :seed_helper do
end
end
describe '#list_refs' do
it 'returns a list of branches with their head commit' do
refs = repository.list_refs
reference = refs.first
expect(refs).to be_an(Enumerable)
expect(reference).to be_a(Gitaly::ListRefsResponse::Reference)
expect(reference.name).to be_a(String)
expect(reference.target).to be_a(String)
end
end
describe '#set_full_path' do
before do
repository_rugged.config["gitlab.fullpath"] = repository_path
......
......@@ -252,6 +252,26 @@ RSpec.describe Gitlab::GitalyClient::RefService do
end
end
describe '#list_refs' do
it 'sends a list_refs message' do
expect_any_instance_of(Gitaly::RefService::Stub)
.to receive(:list_refs)
.with(gitaly_request_with_params(patterns: ['refs/heads/']), kind_of(Hash))
.and_call_original
client.list_refs
end
it 'accepts a patterns argument' do
expect_any_instance_of(Gitaly::RefService::Stub)
.to receive(:list_refs)
.with(gitaly_request_with_params(patterns: ['refs/tags/']), kind_of(Hash))
.and_call_original
client.list_refs([Gitlab::Git::TAG_REF_PREFIX])
end
end
describe '#pack_refs' do
it 'sends a pack_refs message' do
expect_any_instance_of(Gitaly::RefService::Stub)
......
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