Commit 98c0eb0f authored by Valery Sizov's avatar Valery Sizov

BitBucket refactoring. Iteration 3

parent b12d6541
...@@ -6,35 +6,26 @@ module Bitbucket ...@@ -6,35 +6,26 @@ module Bitbucket
def issues(repo) def issues(repo)
path = "/repositories/#{repo}/issues" path = "/repositories/#{repo}/issues"
paginator = Paginator.new(connection, path, :issue) get_collection(path, :issue)
Collection.new(paginator)
end end
def issue_comments(repo, issue_id) def issue_comments(repo, issue_id)
path = "/repositories/#{repo}/issues/#{issue_id}/comments" path = "/repositories/#{repo}/issues/#{issue_id}/comments"
paginator = Paginator.new(connection, path, :comment) get_collection(path, :comment)
Collection.new(paginator)
end end
def pull_requests(repo) def pull_requests(repo)
path = "/repositories/#{repo}/pullrequests?state=ALL" path = "/repositories/#{repo}/pullrequests?state=ALL"
paginator = Paginator.new(connection, path, :pull_request) get_collection(path, :pull_request)
Collection.new(paginator)
end end
def pull_request_comments(repo, pull_request) def pull_request_comments(repo, pull_request)
path = "/repositories/#{repo}/pullrequests/#{pull_request}/comments" path = "/repositories/#{repo}/pullrequests/#{pull_request}/comments"
paginator = Paginator.new(connection, path, :pull_request_comment) get_collection(path, :pull_request_comment)
Collection.new(paginator)
end end
def pull_request_diff(repo, pull_request) def pull_request_diff(repo, pull_request)
path = "/repositories/#{repo}/pullrequests/#{pull_request}/diff" path = "/repositories/#{repo}/pullrequests/#{pull_request}/diff"
connection.get(path) connection.get(path)
end end
...@@ -45,9 +36,7 @@ module Bitbucket ...@@ -45,9 +36,7 @@ module Bitbucket
def repos def repos
path = "/repositories/#{user.username}" path = "/repositories/#{user.username}"
paginator = Paginator.new(connection, path, :repo) get_collection(path, :repo)
Collection.new(paginator)
end end
def user def user
...@@ -60,5 +49,10 @@ module Bitbucket ...@@ -60,5 +49,10 @@ module Bitbucket
private private
attr_reader :connection attr_reader :connection
def get_collection(path, type)
paginator = Paginator.new(connection, path, type)
Collection.new(paginator)
end
end end
end end
...@@ -3,7 +3,7 @@ module Bitbucket ...@@ -3,7 +3,7 @@ module Bitbucket
def initialize(paginator) def initialize(paginator)
super() do |yielder| super() do |yielder|
loop do loop do
paginator.next.each { |item| yielder << item } paginator.items.each { |item| yielder << item }
end end
end end
......
...@@ -11,7 +11,7 @@ module Bitbucket ...@@ -11,7 +11,7 @@ module Bitbucket
connection.set_default_query_parameters(pagelen: PAGE_LENGTH, sort: :created_on) connection.set_default_query_parameters(pagelen: PAGE_LENGTH, sort: :created_on)
end end
def next def items
raise StopIteration unless has_next_page? raise StopIteration unless has_next_page?
@page = fetch_next_page @page = fetch_next_page
......
...@@ -50,7 +50,7 @@ module Gitlab ...@@ -50,7 +50,7 @@ module Gitlab
if issue.persisted? if issue.persisted?
client.issue_comments(repo, issue.iid).each do |comment| client.issue_comments(repo, issue.iid).each do |comment|
# The note can be blank for issue service messages like "Chenged title: ..." # The note can be blank for issue service messages like "Changed title: ..."
# We would like to import those comments as well but there is no any # We would like to import those comments as well but there is no any
# specific parameter that would allow to process them, it's just an empty comment. # specific parameter that would allow to process them, it's just an empty comment.
# To prevent our importer from just crashing or from creating useless empty comments # To prevent our importer from just crashing or from creating useless empty comments
...@@ -70,8 +70,8 @@ module Gitlab ...@@ -70,8 +70,8 @@ module Gitlab
end end
end end
end end
rescue ActiveRecord::RecordInvalid rescue ActiveRecord::RecordInvalid => e
nil Rails.logger.error("Bitbucket importer ERROR in #{project.path_with_namespace}: Couldn't import record properly #{e.message}")
end end
def import_pull_requests def import_pull_requests
......
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