Commit e39f0240 authored by Valery Sizov's avatar Valery Sizov

BB importer: Adding created_by only when used is not found[ci skip]

parent 0057ed1e
...@@ -5,6 +5,10 @@ module Bitbucket ...@@ -5,6 +5,10 @@ module Bitbucket
@raw = raw @raw = raw
end end
def user_representation(raw)
User.new(raw)
end
def self.decorate(entries) def self.decorate(entries)
entries.map { |entry| new(entry)} entries.map { |entry| new(entry)}
end end
......
...@@ -2,7 +2,7 @@ module Bitbucket ...@@ -2,7 +2,7 @@ module Bitbucket
module Representation module Representation
class Comment < Representation::Base class Comment < Representation::Base
def author def author
user.fetch('username', 'Anonymous') user_representation(user)
end end
def note def note
......
...@@ -12,7 +12,7 @@ module Bitbucket ...@@ -12,7 +12,7 @@ module Bitbucket
end end
def author def author
raw.dig('reporter', 'username') || 'Anonymous' user_representation(raw.fetch('reporter', {}))
end end
def description def description
......
...@@ -2,7 +2,7 @@ module Bitbucket ...@@ -2,7 +2,7 @@ module Bitbucket
module Representation module Representation
class PullRequest < Representation::Base class PullRequest < Representation::Base
def author def author
raw.fetch('author', {}).fetch('username', 'Anonymous') user_representation(raw.fetch('author', {}))
end end
def description def description
......
...@@ -2,7 +2,11 @@ module Bitbucket ...@@ -2,7 +2,11 @@ module Bitbucket
module Representation module Representation
class User < Representation::Base class User < Representation::Base
def username def username
raw['username'] raw['username'] || 'Anonymous'
end
def uuid
raw['uuid']
end end
end end
end end
......
...@@ -24,15 +24,23 @@ module Gitlab ...@@ -24,15 +24,23 @@ module Gitlab
private private
def gitlab_user_id(project, bitbucket_id) def gitlab_user_id(project, user)
if bitbucket_id if user.uuid
user = User.joins(:identities).find_by("identities.extern_uid = ? AND identities.provider = 'bitbucket'", bitbucket_id.to_s) user = find_user_by_uuid(user.uuid)
(user && user.id) || project.creator_id (user && user.id) || project.creator_id
else else
project.creator_id project.creator_id
end end
end end
def find_user_by_uuid(uuid)
User.joins(:identities).find_by("identities.extern_uid = ? AND identities.provider = 'bitbucket'", uuid)
end
def existing_gitlab_user?(user)
user.uuid && find_user_by_uuid(user.uuid)
end
def repo def repo
@repo ||= client.repo(project.import_source) @repo ||= client.repo(project.import_source)
end end
...@@ -43,7 +51,8 @@ module Gitlab ...@@ -43,7 +51,8 @@ module Gitlab
create_labels create_labels
client.issues(repo).each do |issue| client.issues(repo).each do |issue|
description = @formatter.author_line(issue.author) description = ''
description += @formatter.author_line(issue.author.username) unless existing_gitlab_user?(issue.author)
description += issue.description description += issue.description
label_name = issue.kind label_name = issue.kind
...@@ -69,7 +78,8 @@ module Gitlab ...@@ -69,7 +78,8 @@ module Gitlab
# we do this check. # we do this check.
next unless comment.note.present? next unless comment.note.present?
note = @formatter.author_line(comment.author) note = ''
note += @formatter.author_line(comment.author.username) unless existing_gitlab_user?(comment.author)
note += comment.note note += comment.note
issue.notes.create!( issue.notes.create!(
...@@ -97,7 +107,8 @@ module Gitlab ...@@ -97,7 +107,8 @@ module Gitlab
pull_requests.each do |pull_request| pull_requests.each do |pull_request|
begin begin
description = @formatter.author_line(pull_request.author) description = ''
description += @formatter.author_line(pull_request.author.username) unless existing_gitlab_user?(pull_request.author)
description += pull_request.description description += pull_request.description
merge_request = project.merge_requests.create( merge_request = project.merge_requests.create(
......
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