summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorValery Sizov <valery@gitlab.com>2016-12-14 12:35:10 +0200
committerValery Sizov <valery@gitlab.com>2016-12-14 12:35:13 +0200
commit8f0cef0b6e5e950efdf3ebfe8f9f846095fff9d9 (patch)
tree178908c7184444bd71b23e62727b69a2e324d6af
parentf20ea1f5cb354db0afe18e4021e1d2fb439c2e06 (diff)
downloadgitlab-ce-8f0cef0b6e5e950efdf3ebfe8f9f846095fff9d9.tar.gz
BB importer: Refactoring user importing logic[ci skip]
-rw-r--r--lib/bitbucket/representation/base.rb4
-rw-r--r--lib/bitbucket/representation/comment.rb2
-rw-r--r--lib/bitbucket/representation/issue.rb2
-rw-r--r--lib/bitbucket/representation/pull_request.rb2
-rw-r--r--lib/bitbucket/representation/user.rb6
-rw-r--r--lib/gitlab/bitbucket_import/importer.rb20
6 files changed, 14 insertions, 22 deletions
diff --git a/lib/bitbucket/representation/base.rb b/lib/bitbucket/representation/base.rb
index fd622d333da..94adaacc9b5 100644
--- a/lib/bitbucket/representation/base.rb
+++ b/lib/bitbucket/representation/base.rb
@@ -5,10 +5,6 @@ module Bitbucket
@raw = raw
end
- def user_representation(raw)
- User.new(raw)
- end
-
def self.decorate(entries)
entries.map { |entry| new(entry)}
end
diff --git a/lib/bitbucket/representation/comment.rb b/lib/bitbucket/representation/comment.rb
index bc40f891cd3..3c75e9368fa 100644
--- a/lib/bitbucket/representation/comment.rb
+++ b/lib/bitbucket/representation/comment.rb
@@ -2,7 +2,7 @@ module Bitbucket
module Representation
class Comment < Representation::Base
def author
- user_representation(user)
+ user['username']
end
def note
diff --git a/lib/bitbucket/representation/issue.rb b/lib/bitbucket/representation/issue.rb
index 90adfa3331a..ffe8a65d839 100644
--- a/lib/bitbucket/representation/issue.rb
+++ b/lib/bitbucket/representation/issue.rb
@@ -12,7 +12,7 @@ module Bitbucket
end
def author
- user_representation(raw.fetch('reporter', {}))
+ raw.dig('reporter', 'username')
end
def description
diff --git a/lib/bitbucket/representation/pull_request.rb b/lib/bitbucket/representation/pull_request.rb
index 96992003d24..e37c9a62c0e 100644
--- a/lib/bitbucket/representation/pull_request.rb
+++ b/lib/bitbucket/representation/pull_request.rb
@@ -2,7 +2,7 @@ module Bitbucket
module Representation
class PullRequest < Representation::Base
def author
- user_representation(raw.fetch('author', {}))
+ raw.dig('author', 'username')
end
def description
diff --git a/lib/bitbucket/representation/user.rb b/lib/bitbucket/representation/user.rb
index 6025a9f0653..ba6b7667b49 100644
--- a/lib/bitbucket/representation/user.rb
+++ b/lib/bitbucket/representation/user.rb
@@ -2,11 +2,7 @@ module Bitbucket
module Representation
class User < Representation::Base
def username
- raw['username'] || 'Anonymous'
- end
-
- def uuid
- raw['uuid']
+ raw['username']
end
end
end
diff --git a/lib/gitlab/bitbucket_import/importer.rb b/lib/gitlab/bitbucket_import/importer.rb
index 519a109c0c8..b6a0b122cdb 100644
--- a/lib/gitlab/bitbucket_import/importer.rb
+++ b/lib/gitlab/bitbucket_import/importer.rb
@@ -24,21 +24,21 @@ module Gitlab
private
- def gitlab_user_id(project, user)
- if user.uuid
- user = find_user_by_uuid(user.uuid)
+ def gitlab_user_id(project, username)
+ if username
+ user = find_user(username)
(user && user.id) || project.creator_id
else
project.creator_id
end
end
- def find_user_by_uuid(uuid)
- User.joins(:identities).find_by("identities.extern_uid = ? AND identities.provider = 'bitbucket'", uuid)
+ def find_user(username)
+ User.joins(:identities).find_by("identities.extern_uid = ? AND identities.provider = 'bitbucket'", username)
end
- def existing_gitlab_user?(user)
- user.uuid && find_user_by_uuid(user.uuid)
+ def existing_gitlab_user?(username)
+ username && find_user(username)
end
def repo
@@ -52,7 +52,7 @@ module Gitlab
client.issues(repo).each do |issue|
description = ''
- description += @formatter.author_line(issue.author.username) unless existing_gitlab_user?(issue.author)
+ description += @formatter.author_line(issue.author) unless existing_gitlab_user?(issue.author)
description += issue.description
label_name = issue.kind
@@ -79,7 +79,7 @@ module Gitlab
next unless comment.note.present?
note = ''
- note += @formatter.author_line(comment.author.username) unless existing_gitlab_user?(comment.author)
+ note += @formatter.author_line(comment.author) unless existing_gitlab_user?(comment.author)
note += comment.note
issue.notes.create!(
@@ -108,7 +108,7 @@ module Gitlab
pull_requests.each do |pull_request|
begin
description = ''
- description += @formatter.author_line(pull_request.author.username) unless existing_gitlab_user?(pull_request.author)
+ description += @formatter.author_line(pull_request.author) unless existing_gitlab_user?(pull_request.author)
description += pull_request.description
merge_request = project.merge_requests.create(