summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorValery Sizov <valery@gitlab.com>2016-12-07 14:00:06 +0200
committerValery Sizov <valery@gitlab.com>2016-12-07 14:00:06 +0200
commitb12d6541835024eb74384551b84bf0e74747d0c3 (patch)
treecde3a9635d616f20bf8c747221d475e0c852b86b
parent67b7637e5d7d3cf3e3f5cde6e7f984ece368c48c (diff)
downloadgitlab-ce-b12d6541835024eb74384551b84bf0e74747d0c3.tar.gz
BitBuckpet importer. Refactoring. Iteration 2
-rw-r--r--app/controllers/import/bitbucket_controller.rb2
-rw-r--r--lib/bitbucket/client.rb6
-rw-r--r--lib/bitbucket/page.rb6
-rw-r--r--lib/bitbucket/paginator.rb4
-rw-r--r--lib/bitbucket/representation/base.rb4
-rw-r--r--lib/bitbucket/representation/url.rb9
-rw-r--r--lib/gitlab/bitbucket_import/importer.rb7
7 files changed, 18 insertions, 20 deletions
diff --git a/app/controllers/import/bitbucket_controller.rb b/app/controllers/import/bitbucket_controller.rb
index 9c97a97a5dd..12716d60e7d 100644
--- a/app/controllers/import/bitbucket_controller.rb
+++ b/app/controllers/import/bitbucket_controller.rb
@@ -62,7 +62,7 @@ class Import::BitbucketController < Import::BaseController
end
def provider
- Gitlab.config.omniauth.providers.find { |provider| provider.name == 'bitbucket' }
+ Gitlab::OAuth::Provider.config_for('bitbucket')
end
def options
diff --git a/lib/bitbucket/client.rb b/lib/bitbucket/client.rb
index 9fa44506374..3457c2c6454 100644
--- a/lib/bitbucket/client.rb
+++ b/lib/bitbucket/client.rb
@@ -13,11 +13,9 @@ module Bitbucket
def issue_comments(repo, issue_id)
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|
- Representation::Comment.new(connection.get(comment_url.to_s))
- end
+ Collection.new(paginator)
end
def pull_requests(repo)
diff --git a/lib/bitbucket/page.rb b/lib/bitbucket/page.rb
index 49d083cc66f..8f50f67f84d 100644
--- a/lib/bitbucket/page.rb
+++ b/lib/bitbucket/page.rb
@@ -18,14 +18,12 @@ module Bitbucket
private
def parse_attrs(raw)
- attrs = %w(size page pagelen next previous)
- attrs.map { |attr| { attr.to_sym => raw[attr] } }.reduce(&:merge)
+ raw.slice(*%w(size page pagelen next previous)).symbolize_keys
end
def parse_values(raw, bitbucket_rep_class)
return [] unless raw['values'] && raw['values'].is_a?(Array)
-
- raw['values'].map { |hash| bitbucket_rep_class.new(hash) }
+ bitbucket_rep_class.decorate(raw['values'])
end
def representation_class(type)
diff --git a/lib/bitbucket/paginator.rb b/lib/bitbucket/paginator.rb
index d0e23007ff8..37f12328447 100644
--- a/lib/bitbucket/paginator.rb
+++ b/lib/bitbucket/paginator.rb
@@ -26,12 +26,12 @@ module Bitbucket
page.nil? || page.next?
end
- def page_url
+ def next_url
page.nil? ? url : page.next
end
def fetch_next_page
- parsed_response = connection.get(page_url)
+ parsed_response = connection.get(next_url)
Page.new(parsed_response, type)
end
end
diff --git a/lib/bitbucket/representation/base.rb b/lib/bitbucket/representation/base.rb
index 7b639492d38..94adaacc9b5 100644
--- a/lib/bitbucket/representation/base.rb
+++ b/lib/bitbucket/representation/base.rb
@@ -5,6 +5,10 @@ module Bitbucket
@raw = raw
end
+ def self.decorate(entries)
+ entries.map { |entry| new(entry)}
+ end
+
private
attr_reader :raw
diff --git a/lib/bitbucket/representation/url.rb b/lib/bitbucket/representation/url.rb
deleted file mode 100644
index 24ae1048013..00000000000
--- a/lib/bitbucket/representation/url.rb
+++ /dev/null
@@ -1,9 +0,0 @@
-module Bitbucket
- module Representation
- class Url < Representation::Base
- def to_s
- raw.dig('links', 'self', 'href')
- end
- end
- end
-end
diff --git a/lib/gitlab/bitbucket_import/importer.rb b/lib/gitlab/bitbucket_import/importer.rb
index 0f583b07e93..825d43e6589 100644
--- a/lib/gitlab/bitbucket_import/importer.rb
+++ b/lib/gitlab/bitbucket_import/importer.rb
@@ -50,6 +50,13 @@ module Gitlab
if issue.persisted?
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 += comment.note