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/groups')
-rw-r--r--lib/bulk_imports/groups/graphql/get_projects_query.rb50
-rw-r--r--lib/bulk_imports/groups/pipelines/entity_finisher.rb49
-rw-r--r--lib/bulk_imports/groups/pipelines/project_entities_pipeline.rb28
-rw-r--r--lib/bulk_imports/groups/stage.rb65
4 files changed, 143 insertions, 49 deletions
diff --git a/lib/bulk_imports/groups/graphql/get_projects_query.rb b/lib/bulk_imports/groups/graphql/get_projects_query.rb
new file mode 100644
index 00000000000..4cec1ad1462
--- /dev/null
+++ b/lib/bulk_imports/groups/graphql/get_projects_query.rb
@@ -0,0 +1,50 @@
+# frozen_string_literal: true
+
+module BulkImports
+ module Groups
+ module Graphql
+ module GetProjectsQuery
+ extend self
+
+ def to_s
+ <<-'GRAPHQL'
+ query($full_path: ID!, $cursor: String, $per_page: Int) {
+ group(fullPath: $full_path) {
+ projects(includeSubgroups: false, first: $per_page, after: $cursor) {
+ page_info: pageInfo {
+ next_page: endCursor
+ has_next_page: hasNextPage
+ }
+ nodes {
+ name
+ full_path: fullPath
+ }
+ }
+ }
+ }
+ GRAPHQL
+ end
+
+ def variables(context)
+ {
+ full_path: context.entity.source_full_path,
+ cursor: context.tracker.next_page,
+ per_page: ::BulkImports::Tracker::DEFAULT_PAGE_SIZE
+ }
+ end
+
+ def base_path
+ %w[data group projects]
+ end
+
+ def data_path
+ base_path << 'nodes'
+ end
+
+ def page_info_path
+ base_path << 'page_info'
+ end
+ end
+ end
+ end
+end
diff --git a/lib/bulk_imports/groups/pipelines/entity_finisher.rb b/lib/bulk_imports/groups/pipelines/entity_finisher.rb
deleted file mode 100644
index 1a709179bf9..00000000000
--- a/lib/bulk_imports/groups/pipelines/entity_finisher.rb
+++ /dev/null
@@ -1,49 +0,0 @@
-# frozen_string_literal: true
-
-module BulkImports
- module Groups
- module Pipelines
- class EntityFinisher
- def self.ndjson_pipeline?
- false
- end
-
- def initialize(context)
- @context = context
- @entity = @context.entity
- @trackers = @entity.trackers
- end
-
- def run
- return if entity.finished? || entity.failed?
-
- if all_other_trackers_failed?
- entity.fail_op!
- else
- entity.finish!
- end
-
- logger.info(
- bulk_import_id: context.bulk_import.id,
- bulk_import_entity_id: context.entity.id,
- bulk_import_entity_type: context.entity.source_type,
- pipeline_class: self.class.name,
- message: "Entity #{entity.status_name}"
- )
- end
-
- private
-
- attr_reader :context, :entity, :trackers
-
- def logger
- @logger ||= Gitlab::Import::Logger.build
- end
-
- def all_other_trackers_failed?
- trackers.where.not(relation: self.class.name).all? { |tracker| tracker.failed? } # rubocop: disable CodeReuse/ActiveRecord
- end
- end
- end
- end
-end
diff --git a/lib/bulk_imports/groups/pipelines/project_entities_pipeline.rb b/lib/bulk_imports/groups/pipelines/project_entities_pipeline.rb
new file mode 100644
index 00000000000..c318675e649
--- /dev/null
+++ b/lib/bulk_imports/groups/pipelines/project_entities_pipeline.rb
@@ -0,0 +1,28 @@
+# frozen_string_literal: true
+
+module BulkImports
+ module Groups
+ module Pipelines
+ class ProjectEntitiesPipeline
+ include Pipeline
+
+ extractor Common::Extractors::GraphqlExtractor, query: Graphql::GetProjectsQuery
+ transformer Common::Transformers::ProhibitedAttributesTransformer
+
+ def transform(context, data)
+ {
+ source_type: :project_entity,
+ source_full_path: data['full_path'],
+ destination_name: data['name'],
+ destination_namespace: context.entity.group.full_path,
+ parent_id: context.entity.id
+ }
+ end
+
+ def load(context, data)
+ context.bulk_import.entities.create!(data)
+ end
+ end
+ end
+ end
+end
diff --git a/lib/bulk_imports/groups/stage.rb b/lib/bulk_imports/groups/stage.rb
new file mode 100644
index 00000000000..8c3b6975b73
--- /dev/null
+++ b/lib/bulk_imports/groups/stage.rb
@@ -0,0 +1,65 @@
+# frozen_string_literal: true
+
+module BulkImports
+ module Groups
+ class Stage < ::BulkImports::Stage
+ private
+
+ def config
+ @config ||= {
+ group: {
+ pipeline: BulkImports::Groups::Pipelines::GroupPipeline,
+ stage: 0
+ },
+ avatar: {
+ pipeline: BulkImports::Groups::Pipelines::GroupAvatarPipeline,
+ stage: 1
+ },
+ subgroups: {
+ pipeline: BulkImports::Groups::Pipelines::SubgroupEntitiesPipeline,
+ stage: 1
+ },
+ members: {
+ pipeline: BulkImports::Groups::Pipelines::MembersPipeline,
+ stage: 1
+ },
+ labels: {
+ pipeline: BulkImports::Groups::Pipelines::LabelsPipeline,
+ stage: 1
+ },
+ milestones: {
+ pipeline: BulkImports::Groups::Pipelines::MilestonesPipeline,
+ stage: 1
+ },
+ badges: {
+ pipeline: BulkImports::Groups::Pipelines::BadgesPipeline,
+ stage: 1
+ },
+ boards: {
+ pipeline: BulkImports::Groups::Pipelines::BoardsPipeline,
+ stage: 2
+ },
+ finisher: {
+ pipeline: BulkImports::Common::Pipelines::EntityFinisher,
+ stage: 3
+ }
+ }.merge(project_entities_pipeline)
+ end
+
+ def project_entities_pipeline
+ if ::Feature.enabled?(:bulk_import_projects, default_enabled: :yaml)
+ {
+ project_entities: {
+ pipeline: BulkImports::Groups::Pipelines::ProjectEntitiesPipeline,
+ stage: 1
+ }
+ }
+ else
+ {}
+ end
+ end
+ end
+ end
+end
+
+::BulkImports::Groups::Stage.prepend_mod_with('BulkImports::Groups::Stage')