summaryrefslogtreecommitdiff
path: root/lib/bitbucket
diff options
context:
space:
mode:
authorValery Sizov <valery@gitlab.com>2016-12-07 15:54:32 +0200
committerValery Sizov <valery@gitlab.com>2016-12-07 15:54:32 +0200
commit98c0eb0f75692b1281adda9bfb75e1fcc12cec6d (patch)
tree3281121be29fa533c5e1d5fd5e8fc8874fb5b34d /lib/bitbucket
parentb12d6541835024eb74384551b84bf0e74747d0c3 (diff)
downloadgitlab-ce-98c0eb0f75692b1281adda9bfb75e1fcc12cec6d.tar.gz
BitBucket refactoring. Iteration 3
Diffstat (limited to 'lib/bitbucket')
-rw-r--r--lib/bitbucket/client.rb26
-rw-r--r--lib/bitbucket/collection.rb2
-rw-r--r--lib/bitbucket/paginator.rb2
3 files changed, 12 insertions, 18 deletions
diff --git a/lib/bitbucket/client.rb b/lib/bitbucket/client.rb
index 3457c2c6454..e23da4556aa 100644
--- a/lib/bitbucket/client.rb
+++ b/lib/bitbucket/client.rb
@@ -6,35 +6,26 @@ module Bitbucket
def issues(repo)
path = "/repositories/#{repo}/issues"
- paginator = Paginator.new(connection, path, :issue)
-
- Collection.new(paginator)
+ get_collection(path, :issue)
end
def issue_comments(repo, issue_id)
path = "/repositories/#{repo}/issues/#{issue_id}/comments"
- paginator = Paginator.new(connection, path, :comment)
-
- Collection.new(paginator)
+ get_collection(path, :comment)
end
def pull_requests(repo)
path = "/repositories/#{repo}/pullrequests?state=ALL"
- paginator = Paginator.new(connection, path, :pull_request)
-
- Collection.new(paginator)
+ get_collection(path, :pull_request)
end
def pull_request_comments(repo, pull_request)
path = "/repositories/#{repo}/pullrequests/#{pull_request}/comments"
- paginator = Paginator.new(connection, path, :pull_request_comment)
-
- Collection.new(paginator)
+ get_collection(path, :pull_request_comment)
end
def pull_request_diff(repo, pull_request)
path = "/repositories/#{repo}/pullrequests/#{pull_request}/diff"
-
connection.get(path)
end
@@ -45,9 +36,7 @@ module Bitbucket
def repos
path = "/repositories/#{user.username}"
- paginator = Paginator.new(connection, path, :repo)
-
- Collection.new(paginator)
+ get_collection(path, :repo)
end
def user
@@ -60,5 +49,10 @@ module Bitbucket
private
attr_reader :connection
+
+ def get_collection(path, type)
+ paginator = Paginator.new(connection, path, type)
+ Collection.new(paginator)
+ end
end
end
diff --git a/lib/bitbucket/collection.rb b/lib/bitbucket/collection.rb
index 9cc8947417c..3a9379ff680 100644
--- a/lib/bitbucket/collection.rb
+++ b/lib/bitbucket/collection.rb
@@ -3,7 +3,7 @@ module Bitbucket
def initialize(paginator)
super() do |yielder|
loop do
- paginator.next.each { |item| yielder << item }
+ paginator.items.each { |item| yielder << item }
end
end
diff --git a/lib/bitbucket/paginator.rb b/lib/bitbucket/paginator.rb
index 37f12328447..641a6ed79d6 100644
--- a/lib/bitbucket/paginator.rb
+++ b/lib/bitbucket/paginator.rb
@@ -11,7 +11,7 @@ module Bitbucket
connection.set_default_query_parameters(pagelen: PAGE_LENGTH, sort: :created_on)
end
- def next
+ def items
raise StopIteration unless has_next_page?
@page = fetch_next_page