From 378c9ae87dd4bf5e0b318cc256a1e6aa94ae37f5 Mon Sep 17 00:00:00 2001 From: Rodrigo Tomonari Date: Thu, 12 Dec 2024 11:12:25 -0300 Subject: [PATCH 1/2] Assign imported contributions to the ImportUser Assign all contributions to the import user when the destination is a personal namespace. --- lib/gitlab/import/source_user_mapper.rb | 2 +- .../lib/gitlab/import/source_user_mapper_spec.rb | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/gitlab/import/source_user_mapper.rb b/lib/gitlab/import/source_user_mapper.rb index d21b0c60895f11..59bd0add07025f 100644 --- a/lib/gitlab/import/source_user_mapper.rb +++ b/lib/gitlab/import/source_user_mapper.rb @@ -107,7 +107,7 @@ def create_source_user_mapping(source_name, source_username, source_user_identif end def create_placeholder_user(import_source_user) - return namespace_import_user if placeholder_user_limit_exceeded? + return namespace_import_user if placeholder_user_limit_exceeded? || namespace.user_namespace? Gitlab::Import::PlaceholderUserCreator.new(import_source_user).execute end diff --git a/spec/lib/gitlab/import/source_user_mapper_spec.rb b/spec/lib/gitlab/import/source_user_mapper_spec.rb index abbd6f71431868..ac552ea3954df9 100644 --- a/spec/lib/gitlab/import/source_user_mapper_spec.rb +++ b/spec/lib/gitlab/import/source_user_mapper_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' RSpec.describe Gitlab::Import::SourceUserMapper, :request_store, feature_category: :importers do - let_it_be(:namespace) { create(:namespace) } + let_it_be(:namespace) { create(:group) } let_it_be(:import_type) { 'github' } let_it_be(:source_hostname) { 'https://github.com' } @@ -200,6 +200,20 @@ end end + context 'when namespace is a personal namespace' do + let_it_be(:namespace) { create(:namespace) } + let_it_be(:import_user) { create(:namespace_import_user, namespace: namespace).import_user } + + it 'does not create any placeholder users and assigns the import user' do + expect { find_or_create_source_user } + .to change { Import::SourceUser.count }.by(1) + + new_import_source_user = Import::SourceUser.last + + expect(new_import_source_user.placeholder_user).to eq(import_user) + end + end + context 'when ActiveRecord::RecordNotUnique exception is raised during the source user creation' do before do allow_next_instance_of(::Import::SourceUser) do |source_user| -- GitLab From 30a0a454113576bebd4aec40c2b262d21cd458d1 Mon Sep 17 00:00:00 2001 From: Rodrigo Tomonari Date: Thu, 12 Dec 2024 17:22:46 -0300 Subject: [PATCH 2/2] Update specs to not use personal namespace --- .../pull_requests/review_request_importer_spec.rb | 2 +- .../legacy_github_import/issue_formatter_spec.rb | 10 ++++------ .../pull_request_formatter_spec.rb | 2 ++ .../gitlab/legacy_github_import/user_formatter_spec.rb | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/spec/lib/gitlab/github_import/importer/pull_requests/review_request_importer_spec.rb b/spec/lib/gitlab/github_import/importer/pull_requests/review_request_importer_spec.rb index 4f71c6a68f9a33..c449e1d2d8c4f3 100644 --- a/spec/lib/gitlab/github_import/importer/pull_requests/review_request_importer_spec.rb +++ b/spec/lib/gitlab/github_import/importer/pull_requests/review_request_importer_spec.rb @@ -5,7 +5,7 @@ RSpec.describe Gitlab::GithubImport::Importer::PullRequests::ReviewRequestImporter, :clean_gitlab_redis_shared_state, feature_category: :importers do include Import::UserMappingHelper - let_it_be(:project) { create(:project, :with_import_url, :import_user_mapping_enabled) } + let_it_be(:project) { create(:project, :with_import_url, :import_user_mapping_enabled, :in_group) } let_it_be(:reviewer) { create(:user, username: 'alice') } let_it_be(:source_user) do create( diff --git a/spec/lib/gitlab/legacy_github_import/issue_formatter_spec.rb b/spec/lib/gitlab/legacy_github_import/issue_formatter_spec.rb index cc61e6c07c7879..24a5317836e161 100644 --- a/spec/lib/gitlab/legacy_github_import/issue_formatter_spec.rb +++ b/spec/lib/gitlab/legacy_github_import/issue_formatter_spec.rb @@ -10,9 +10,8 @@ :project, :with_import_url, :import_user_mapping_enabled, - import_type: ::Import::SOURCE_GITEA, - namespace: create(:namespace, path: 'octocat') - ) + :in_group, + import_type: ::Import::SOURCE_GITEA) end let_it_be(:source_user_mapper) do @@ -258,10 +257,9 @@ create( :project, :with_import_url, + :in_group, :import_user_mapping_enabled, - import_type: ::Import::SOURCE_GITHUB, - namespace: create(:namespace, path: 'octocat-github') - ) + import_type: ::Import::SOURCE_GITHUB) end let_it_be(:source_user_mapper) do diff --git a/spec/lib/gitlab/legacy_github_import/pull_request_formatter_spec.rb b/spec/lib/gitlab/legacy_github_import/pull_request_formatter_spec.rb index cdb983788039fa..e4cdf05c1466b0 100644 --- a/spec/lib/gitlab/legacy_github_import/pull_request_formatter_spec.rb +++ b/spec/lib/gitlab/legacy_github_import/pull_request_formatter_spec.rb @@ -10,6 +10,7 @@ :project, :repository, :with_import_url, + :in_group, :import_user_mapping_enabled, import_type: ::Import::SOURCE_GITEA ) @@ -351,6 +352,7 @@ :project, :repository, :with_import_url, + :in_group, :import_user_mapping_enabled, import_type: ::Import::SOURCE_GITHUB ) diff --git a/spec/lib/gitlab/legacy_github_import/user_formatter_spec.rb b/spec/lib/gitlab/legacy_github_import/user_formatter_spec.rb index 7f650cf8116696..7f5306e58510f7 100644 --- a/spec/lib/gitlab/legacy_github_import/user_formatter_spec.rb +++ b/spec/lib/gitlab/legacy_github_import/user_formatter_spec.rb @@ -5,7 +5,7 @@ RSpec.describe Gitlab::LegacyGithubImport::UserFormatter, feature_category: :importers do include Import::GiteaHelper - let_it_be(:project) { create(:project, :import_user_mapping_enabled, import_type: 'gitea') } + let_it_be(:project) { create(:project, :import_user_mapping_enabled, :in_group, import_type: 'gitea') } let_it_be(:source_user_mapper) do Gitlab::Import::SourceUserMapper.new( -- GitLab