Commit b12d6541 authored by Valery Sizov's avatar Valery Sizov

BitBuckpet importer. Refactoring. Iteration 2

parent 67b7637e
...@@ -62,7 +62,7 @@ class Import::BitbucketController < Import::BaseController ...@@ -62,7 +62,7 @@ class Import::BitbucketController < Import::BaseController
end end
def provider def provider
Gitlab.config.omniauth.providers.find { |provider| provider.name == 'bitbucket' } Gitlab::OAuth::Provider.config_for('bitbucket')
end end
def options def options
......
...@@ -13,11 +13,9 @@ module Bitbucket ...@@ -13,11 +13,9 @@ module Bitbucket
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, :url) paginator = Paginator.new(connection, path, :comment)
Collection.new(paginator).map do |comment_url| Collection.new(paginator)
Representation::Comment.new(connection.get(comment_url.to_s))
end
end end
def pull_requests(repo) def pull_requests(repo)
......
...@@ -18,14 +18,12 @@ module Bitbucket ...@@ -18,14 +18,12 @@ module Bitbucket
private private
def parse_attrs(raw) def parse_attrs(raw)
attrs = %w(size page pagelen next previous) raw.slice(*%w(size page pagelen next previous)).symbolize_keys
attrs.map { |attr| { attr.to_sym => raw[attr] } }.reduce(&:merge)
end end
def parse_values(raw, bitbucket_rep_class) def parse_values(raw, bitbucket_rep_class)
return [] unless raw['values'] && raw['values'].is_a?(Array) return [] unless raw['values'] && raw['values'].is_a?(Array)
bitbucket_rep_class.decorate(raw['values'])
raw['values'].map { |hash| bitbucket_rep_class.new(hash) }
end end
def representation_class(type) def representation_class(type)
......
...@@ -26,12 +26,12 @@ module Bitbucket ...@@ -26,12 +26,12 @@ module Bitbucket
page.nil? || page.next? page.nil? || page.next?
end end
def page_url def next_url
page.nil? ? url : page.next page.nil? ? url : page.next
end end
def fetch_next_page def fetch_next_page
parsed_response = connection.get(page_url) parsed_response = connection.get(next_url)
Page.new(parsed_response, type) Page.new(parsed_response, type)
end end
end end
......
...@@ -5,6 +5,10 @@ module Bitbucket ...@@ -5,6 +5,10 @@ module Bitbucket
@raw = raw @raw = raw
end end
def self.decorate(entries)
entries.map { |entry| new(entry)}
end
private private
attr_reader :raw attr_reader :raw
......
module Bitbucket
module Representation
class Url < Representation::Base
def to_s
raw.dig('links', 'self', 'href')
end
end
end
end
...@@ -50,6 +50,13 @@ module Gitlab ...@@ -50,6 +50,13 @@ 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: ..."
# 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.
# To prevent our importer from just crashing or from creating useless empty comments
# we do this check.
next unless comment.note.present?
note = @formatter.author_line(comment.author) note = @formatter.author_line(comment.author)
note += comment.note note += comment.note
......
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