diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-07-31 15:23:51 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-07-31 15:23:51 +0300 |
commit | 920cbcb38960331cd5e9315e63b2d808fd1a1e48 (patch) | |
tree | 7a20d5c4d92257557c0042e3b1b516fb44b34989 /lib/gitlab | |
parent | 34a401c88dd94954363884f1325b92659159bdd7 (diff) |
Add latest changes from gitlab-org/gitlab@16-2-stable-ee
Diffstat (limited to 'lib/gitlab')
4 files changed, 35 insertions, 0 deletions
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 |