summaryrefslogtreecommitdiff
path: root/lib/gitlab/bitbucket_server_import/importer.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/gitlab/bitbucket_server_import/importer.rb')
-rw-r--r--lib/gitlab/bitbucket_server_import/importer.rb43
1 files changed, 30 insertions, 13 deletions
diff --git a/lib/gitlab/bitbucket_server_import/importer.rb b/lib/gitlab/bitbucket_server_import/importer.rb
index 18a1b64729e..aca5a63a424 100644
--- a/lib/gitlab/bitbucket_server_import/importer.rb
+++ b/lib/gitlab/bitbucket_server_import/importer.rb
@@ -61,17 +61,18 @@ module Gitlab
}.to_json)
end
- def gitlab_user_id(email)
- find_user_id(email) || project.creator_id
- end
+ def find_user_id(by:, value:)
+ return unless value
- def find_user_id(email)
- return unless email
+ return users[value] if users.key?(value)
- return users[email] if users.key?(email)
+ user = if by == :email
+ User.find_by_any_email(value, confirmed: true)
+ else
+ User.find_by_username(value)
+ end
- user = User.find_by_any_email(email, confirmed: true)
- users[email] = user&.id
+ users[value] = user&.id
user&.id
end
@@ -197,9 +198,8 @@ module Gitlab
log_info(stage: 'import_bitbucket_pull_requests', message: 'starting', iid: pull_request.iid)
description = ''
- description += @formatter.author_line(pull_request.author) unless find_user_id(pull_request.author_email)
+ description += author_line(pull_request)
description += pull_request.description if pull_request.description
- author_id = gitlab_user_id(pull_request.author_email)
attributes = {
iid: pull_request.iid,
@@ -212,7 +212,7 @@ module Gitlab
target_branch: Gitlab::Git.ref_name(pull_request.target_branch_name),
target_branch_sha: pull_request.target_branch_sha,
state_id: MergeRequest.available_states[pull_request.state],
- author_id: author_id,
+ author_id: author_id(pull_request),
created_at: pull_request.created_at,
updated_at: pull_request.updated_at
}
@@ -254,7 +254,7 @@ module Gitlab
committer = merge_event.committer_email
- user_id = gitlab_user_id(committer)
+ user_id = find_user_id(by: :email, value: committer) || project.creator_id
timestamp = merge_event.merge_timestamp
merge_request.update({ merge_commit_sha: merge_event.merge_commit })
metric = MergeRequest::Metrics.find_or_initialize_by(merge_request: merge_request)
@@ -353,7 +353,7 @@ module Gitlab
end
def pull_request_comment_attributes(comment)
- author = find_user_id(comment.author_email)
+ author = uid(comment)
note = ''
unless author
@@ -397,6 +397,23 @@ module Gitlab
def metrics
@metrics ||= Gitlab::Import::Metrics.new(:bitbucket_server_importer, @project)
end
+
+ def author_line(rep_object)
+ return '' if uid(rep_object)
+
+ @formatter.author_line(rep_object.author)
+ end
+
+ def author_id(rep_object)
+ uid(rep_object) || project.creator_id
+ end
+
+ def uid(rep_object)
+ find_user_id(by: :email, value: rep_object.author_email) unless Feature.enabled?(:bitbucket_server_user_mapping_by_username)
+
+ find_user_id(by: :username, value: rep_object.author_username) ||
+ find_user_id(by: :email, value: rep_object.author_email)
+ end
end
end
end