diff options
Diffstat (limited to 'lib')
5 files changed, 40 insertions, 0 deletions
diff --git a/lib/bitbucket_server/representation/pull_request.rb b/lib/bitbucket_server/representation/pull_request.rb index acbc44f6119..66dba5fefc7 100644 --- a/lib/bitbucket_server/representation/pull_request.rb +++ b/lib/bitbucket_server/representation/pull_request.rb @@ -21,6 +21,10 @@ module BitbucketServer raw['description'] end + def reviewers + raw['reviewers'] + end + def iid raw['id'] end @@ -75,6 +79,7 @@ module BitbucketServer author_email: author_email, author_username: author_username, description: description, + reviewers: reviewers, created_at: created_at, updated_at: updated_at, state: state, diff --git a/lib/gitlab/bitbucket_server_import/importer.rb b/lib/gitlab/bitbucket_server_import/importer.rb index f3253027d57..1871dd3a89d 100644 --- a/lib/gitlab/bitbucket_server_import/importer.rb +++ b/lib/gitlab/bitbucket_server_import/importer.rb @@ -253,6 +253,7 @@ module Gitlab iid: pull_request.iid, title: pull_request.title, description: description, + reviewer_ids: reviewers(pull_request.reviewers), source_project_id: project.id, source_branch: Gitlab::Git.ref_name(pull_request.source_branch_name), source_branch_sha: pull_request.source_branch_sha, @@ -450,6 +451,18 @@ module Gitlab find_user_id(by: :email, value: rep_object.author_email) end end + + def reviewers(reviewers) + return [] unless reviewers.present? + + reviewers.filter_map do |reviewer| + if Feature.enabled?(:bitbucket_server_user_mapping_by_username, type: :ops) + find_user_id(by: :username, value: reviewer.dig('user', 'slug')) + else + find_user_id(by: :email, value: reviewer.dig('user', 'emailAddress')) + end + end + end end end end diff --git a/lib/gitlab/bitbucket_server_import/importers/pull_request_importer.rb b/lib/gitlab/bitbucket_server_import/importers/pull_request_importer.rb index 5d306f98980..34963452192 100644 --- a/lib/gitlab/bitbucket_server_import/importers/pull_request_importer.rb +++ b/lib/gitlab/bitbucket_server_import/importers/pull_request_importer.rb @@ -27,6 +27,7 @@ module Gitlab iid: object[:iid], title: object[:title], description: description, + reviewer_ids: reviewers, source_project_id: project.id, source_branch: Gitlab::Git.ref_name(object[:source_branch_name]), source_branch_sha: object[:source_branch_sha], @@ -55,6 +56,18 @@ module Gitlab formatter.author_line(object[:author]) end + + def reviewers + return [] unless object[:reviewers].present? + + object[:reviewers].filter_map do |reviewer| + if Feature.enabled?(:bitbucket_server_user_mapping_by_username, type: :ops) + user_finder.find_user_id(by: :username, value: reviewer.dig('user', 'slug')) + else + user_finder.find_user_id(by: :email, value: reviewer.dig('user', 'emailAddress')) + end + end + end end end end diff --git a/lib/gitlab/import/merge_request_creator.rb b/lib/gitlab/import/merge_request_creator.rb index 8291372bba9..c6aceaf272c 100644 --- a/lib/gitlab/import/merge_request_creator.rb +++ b/lib/gitlab/import/merge_request_creator.rb @@ -25,12 +25,14 @@ module Gitlab def execute(attributes) source_branch_sha = attributes.delete(:source_branch_sha) target_branch_sha = attributes.delete(:target_branch_sha) + reviewer_ids = attributes.delete(:reviewer_ids) iid = attributes[:iid] merge_request, already_exists = create_merge_request_without_hooks(project, attributes, iid) if merge_request insert_or_replace_git_data(merge_request, source_branch_sha, target_branch_sha, already_exists) + insert_merge_request_reviewers(merge_request, reviewer_ids) end merge_request diff --git a/lib/gitlab/import/merge_request_helpers.rb b/lib/gitlab/import/merge_request_helpers.rb index c5694d95aa1..9fd393c61a0 100644 --- a/lib/gitlab/import/merge_request_helpers.rb +++ b/lib/gitlab/import/merge_request_helpers.rb @@ -62,6 +62,13 @@ module Gitlab diff.save_git_content diff.set_as_latest_diff end + + def insert_merge_request_reviewers(merge_request, reviewers) + return unless reviewers.present? + + rows = reviewers.map { |reviewer_id| { merge_request_id: merge_request.id, user_id: reviewer_id } } + MergeRequestReviewer.insert_all(rows) + end end end end |