summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--changelogs/unreleased/sh-fix-issue-55914.yml5
-rw-r--r--lib/bitbucket_server/paginator.rb12
-rw-r--r--spec/lib/bitbucket_server/paginator_spec.rb11
3 files changed, 25 insertions, 3 deletions
diff --git a/changelogs/unreleased/sh-fix-issue-55914.yml b/changelogs/unreleased/sh-fix-issue-55914.yml
new file mode 100644
index 00000000000..f6f372f59c7
--- /dev/null
+++ b/changelogs/unreleased/sh-fix-issue-55914.yml
@@ -0,0 +1,5 @@
+---
+title: Fix Bitbucket Server import only including first 25 pull requests
+merge_request: 24178
+author:
+type: fixed
diff --git a/lib/bitbucket_server/paginator.rb b/lib/bitbucket_server/paginator.rb
index aa5f84f44b3..9eda1c921b2 100644
--- a/lib/bitbucket_server/paginator.rb
+++ b/lib/bitbucket_server/paginator.rb
@@ -12,7 +12,7 @@ module BitbucketServer
@url = url
@page = nil
@page_offset = page_offset
- @limit = limit || PAGE_LENGTH
+ @limit = limit
@total = 0
end
@@ -34,6 +34,8 @@ module BitbucketServer
attr_reader :connection, :page, :url, :type, :limit
def over_limit?
+ return false unless @limit
+
@limit.positive? && @total >= @limit
end
@@ -42,11 +44,15 @@ module BitbucketServer
end
def starting_offset
- [0, page_offset - 1].max * limit
+ [0, page_offset - 1].max * max_per_page
+ end
+
+ def max_per_page
+ limit || PAGE_LENGTH
end
def fetch_next_page
- parsed_response = connection.get(@url, start: next_offset, limit: @limit)
+ parsed_response = connection.get(@url, start: next_offset, limit: max_per_page)
Page.new(parsed_response, type)
end
end
diff --git a/spec/lib/bitbucket_server/paginator_spec.rb b/spec/lib/bitbucket_server/paginator_spec.rb
index d268d4f23cf..eadd7f68bfb 100644
--- a/spec/lib/bitbucket_server/paginator_spec.rb
+++ b/spec/lib/bitbucket_server/paginator_spec.rb
@@ -30,6 +30,17 @@ describe BitbucketServer::Paginator do
expect { limited.items }.to raise_error(StopIteration)
end
+ it 'does not stop if limit is unspecified' do
+ stub_const("BitbucketServer::Paginator::PAGE_LENGTH", 1)
+ paginator = described_class.new(connection, 'http://more-data', :pull_request, page_offset: 0, limit: nil)
+ allow(paginator).to receive(:fetch_next_page).and_return(first_page, last_page)
+
+ expect(paginator.has_next_page?).to be_truthy
+ expect(paginator.items).to match(['item_1'])
+ expect(paginator.has_next_page?).to be_truthy
+ expect(paginator.items).to match(['item_2'])
+ end
+
it 'calls the connection with different offsets' do
expect(connection).to receive(:get).with('http://more-data', start: 0, limit: BitbucketServer::Paginator::PAGE_LENGTH).and_return(page_attrs)