Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'lib/bulk_imports/projects')
-rw-r--r--lib/bulk_imports/projects/graphql/get_project_query.rb50
-rw-r--r--lib/bulk_imports/projects/pipelines/project_pipeline.rb29
-rw-r--r--lib/bulk_imports/projects/stage.rb24
-rw-r--r--lib/bulk_imports/projects/transformers/project_attributes_transformer.rb24
4 files changed, 127 insertions, 0 deletions
diff --git a/lib/bulk_imports/projects/graphql/get_project_query.rb b/lib/bulk_imports/projects/graphql/get_project_query.rb
new file mode 100644
index 00000000000..2aec496880f
--- /dev/null
+++ b/lib/bulk_imports/projects/graphql/get_project_query.rb
@@ -0,0 +1,50 @@
+# frozen_string_literal: true
+
+module BulkImports
+ module Projects
+ module Graphql
+ module GetProjectQuery
+ extend self
+
+ def to_s
+ <<-'GRAPHQL'
+ query($full_path: ID!) {
+ project(fullPath: $full_path) {
+ description
+ visibility
+ archived
+ created_at: createdAt
+ shared_runners_enabled: sharedRunnersEnabled
+ container_registry_enabled: containerRegistryEnabled
+ only_allow_merge_if_pipeline_succeeds: onlyAllowMergeIfPipelineSucceeds
+ only_allow_merge_if_all_discussions_are_resolved: onlyAllowMergeIfAllDiscussionsAreResolved
+ request_access_enabled: requestAccessEnabled
+ printing_merge_request_link_enabled: printingMergeRequestLinkEnabled
+ remove_source_branch_after_merge: removeSourceBranchAfterMerge
+ autoclose_referenced_issues: autocloseReferencedIssues
+ suggestion_commit_message: suggestionCommitMessage
+ wiki_enabled: wikiEnabled
+ }
+ }
+ GRAPHQL
+ end
+
+ def variables(context)
+ { full_path: context.entity.source_full_path }
+ end
+
+ def base_path
+ %w[data project]
+ end
+
+ def data_path
+ base_path
+ end
+
+ def page_info_path
+ base_path << 'page_info'
+ end
+ end
+ end
+ end
+end
diff --git a/lib/bulk_imports/projects/pipelines/project_pipeline.rb b/lib/bulk_imports/projects/pipelines/project_pipeline.rb
new file mode 100644
index 00000000000..c9da33fe8e3
--- /dev/null
+++ b/lib/bulk_imports/projects/pipelines/project_pipeline.rb
@@ -0,0 +1,29 @@
+# frozen_string_literal: true
+
+module BulkImports
+ module Projects
+ module Pipelines
+ class ProjectPipeline
+ include Pipeline
+
+ abort_on_failure!
+
+ extractor ::BulkImports::Common::Extractors::GraphqlExtractor, query: Graphql::GetProjectQuery
+ transformer ::BulkImports::Common::Transformers::ProhibitedAttributesTransformer
+ transformer ::BulkImports::Projects::Transformers::ProjectAttributesTransformer
+
+ def load(context, data)
+ project = ::Projects::CreateService.new(context.current_user, data).execute
+
+ if project.persisted?
+ context.entity.update!(project: project)
+
+ project
+ else
+ raise(::BulkImports::Error, "Unable to import project #{project.full_path}. #{project.errors.full_messages}.")
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/lib/bulk_imports/projects/stage.rb b/lib/bulk_imports/projects/stage.rb
new file mode 100644
index 00000000000..b606003091b
--- /dev/null
+++ b/lib/bulk_imports/projects/stage.rb
@@ -0,0 +1,24 @@
+# frozen_string_literal: true
+
+module BulkImports
+ module Projects
+ class Stage < ::BulkImports::Stage
+ private
+
+ def config
+ @config ||= {
+ group: {
+ pipeline: BulkImports::Projects::Pipelines::ProjectPipeline,
+ stage: 0
+ },
+ finisher: {
+ pipeline: BulkImports::Common::Pipelines::EntityFinisher,
+ stage: 1
+ }
+ }
+ end
+ end
+ end
+end
+
+::BulkImports::Projects::Stage.prepend_mod_with('BulkImports::Projects::Stage')
diff --git a/lib/bulk_imports/projects/transformers/project_attributes_transformer.rb b/lib/bulk_imports/projects/transformers/project_attributes_transformer.rb
new file mode 100644
index 00000000000..24c55d8dbb1
--- /dev/null
+++ b/lib/bulk_imports/projects/transformers/project_attributes_transformer.rb
@@ -0,0 +1,24 @@
+# frozen_string_literal: true
+
+module BulkImports
+ module Projects
+ module Transformers
+ class ProjectAttributesTransformer
+ PROJECT_IMPORT_TYPE = 'gitlab_project_migration'
+
+ def transform(context, data)
+ entity = context.entity
+ visibility = data.delete('visibility')
+
+ data['name'] = entity.destination_name
+ data['path'] = entity.destination_name.parameterize
+ data['import_type'] = PROJECT_IMPORT_TYPE
+ data['visibility_level'] = Gitlab::VisibilityLevel.string_options[visibility] if visibility.present?
+ data['namespace_id'] = Namespace.find_by_full_path(entity.destination_namespace)&.id if entity.destination_namespace.present?
+
+ data.transform_keys!(&:to_sym)
+ end
+ end
+ end
+ end
+end