Commit b773abc0 authored by Dmitry Gruzd's avatar Dmitry Gruzd

Merge branch '340591_add_tags_pagination_support' into 'master'

Add pagination support for FindAllTagsRequest

See merge request gitlab-org/gitlab!70199
parents 5fb40526 440c1357
......@@ -731,8 +731,8 @@ class Repository
raw_repository.local_branches(sort_by: sort_by, pagination_params: pagination_params)
end
def tags_sorted_by(value)
return raw_repository.tags(sort_by: value) if Feature.enabled?(:tags_finder_gitaly, project, default_enabled: :yaml)
def tags_sorted_by(value, pagination_params = nil)
return raw_repository.tags(sort_by: value, pagination_params: pagination_params) if Feature.enabled?(:tags_finder_gitaly, project, default_enabled: :yaml)
tags_ruby_sort(value)
end
......
......@@ -198,9 +198,9 @@ module Gitlab
# Returns an Array of Tags
#
def tags(sort_by: nil)
def tags(sort_by: nil, pagination_params: nil)
wrapped_gitaly_errors do
gitaly_ref_client.tags(sort_by: sort_by)
gitaly_ref_client.tags(sort_by: sort_by, pagination_params: pagination_params)
end
end
......
......@@ -77,8 +77,8 @@ module Gitlab
consume_find_local_branches_response(response)
end
def tags(sort_by: nil)
request = Gitaly::FindAllTagsRequest.new(repository: @gitaly_repo)
def tags(sort_by: nil, pagination_params: nil)
request = Gitaly::FindAllTagsRequest.new(repository: @gitaly_repo, pagination_params: pagination_params)
request.sort_by = sort_tags_by_param(sort_by) if sort_by
response = GitalyClient.call(@storage, :ref_service, :find_all_tags, request, timeout: GitalyClient.medium_timeout)
......
......@@ -125,7 +125,22 @@ RSpec.describe Gitlab::Git::Repository, :seed_helper do
it 'gets tags from GitalyClient' do
expect_next_instance_of(Gitlab::GitalyClient::RefService) do |service|
expect(service).to receive(:tags).with(sort_by: 'name_asc')
expect(service).to receive(:tags).with(sort_by: 'name_asc', pagination_params: nil)
end
subject
end
end
context 'with pagination option' do
subject { repository.tags(pagination_params: { limit: 5, page_token: 'refs/tags/v1.0.0' }) }
it 'gets tags from GitalyClient' do
expect_next_instance_of(Gitlab::GitalyClient::RefService) do |service|
expect(service).to receive(:tags).with(
sort_by: nil,
pagination_params: { limit: 5, page_token: 'refs/tags/v1.0.0' }
)
end
subject
......
......@@ -190,6 +190,22 @@ RSpec.describe Gitlab::GitalyClient::RefService do
client.tags(sort_by: 'name_asc')
end
end
context 'with pagination option' do
it 'sends a correct find_all_tags message' do
expected_pagination = Gitaly::PaginationParameter.new(
limit: 5,
page_token: 'refs/tags/v1.0.0'
)
expect_any_instance_of(Gitaly::RefService::Stub)
.to receive(:find_all_tags)
.with(gitaly_request_with_params(pagination_params: expected_pagination), kind_of(Hash))
.and_return([])
client.tags(pagination_params: { limit: 5, page_token: 'refs/tags/v1.0.0' })
end
end
end
describe '#branch_names_contains_sha' do
......
......@@ -66,7 +66,7 @@ RSpec.describe Repository do
it { is_expected.not_to include('v1.0.0') }
end
describe 'tags_sorted_by' do
describe '#tags_sorted_by' do
let(:tags_to_compare) { %w[v1.0.0 v1.1.0] }
let(:feature_flag) { true }
......@@ -87,7 +87,9 @@ RSpec.describe Repository do
end
context 'name_asc' do
subject { repository.tags_sorted_by('name_asc').map(&:name) & tags_to_compare }
subject { repository.tags_sorted_by('name_asc', pagination_params).map(&:name) & tags_to_compare }
let(:pagination_params) { nil }
it { is_expected.to eq(['v1.0.0', 'v1.1.0']) }
......@@ -96,6 +98,44 @@ RSpec.describe Repository do
it { is_expected.to eq(['v1.0.0', 'v1.1.0']) }
end
context 'with pagination' do
context 'with limit' do
let(:pagination_params) { { limit: 1 } }
it { is_expected.to eq(['v1.0.0']) }
end
context 'with page token and limit' do
let(:pagination_params) { { page_token: 'refs/tags/v1.0.0', limit: 1 } }
it { is_expected.to eq(['v1.1.0']) }
end
context 'with page token only' do
let(:pagination_params) { { page_token: 'refs/tags/v1.0.0' } }
it 'raises an ArgumentError' do
expect { subject }.to raise_error(ArgumentError)
end
end
context 'with negative limit' do
let(:pagination_params) { { limit: -1 } }
it 'returns all tags' do
is_expected.to eq(['v1.0.0', 'v1.1.0'])
end
end
context 'with unknown token' do
let(:pagination_params) { { page_token: 'unknown' } }
it 'raises an ArgumentError' do
expect { subject }.to raise_error(ArgumentError)
end
end
end
end
context 'updated' do
......
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