diff options
Diffstat (limited to 'lib/bulk_imports/groups')
6 files changed, 40 insertions, 84 deletions
diff --git a/lib/bulk_imports/groups/extractors/subgroups_extractor.rb b/lib/bulk_imports/groups/extractors/subgroups_extractor.rb index e5e2b9fdbd4..db5882d49a9 100644 --- a/lib/bulk_imports/groups/extractors/subgroups_extractor.rb +++ b/lib/bulk_imports/groups/extractors/subgroups_extractor.rb @@ -17,7 +17,7 @@ module BulkImports private def http_client(configuration) - @http_client ||= BulkImports::Clients::Http.new( + @http_client ||= BulkImports::Clients::HTTP.new( uri: configuration.url, token: configuration.access_token, per_page: 100 diff --git a/lib/bulk_imports/groups/graphql/get_labels_query.rb b/lib/bulk_imports/groups/graphql/get_labels_query.rb deleted file mode 100644 index f957cf0be52..00000000000 --- a/lib/bulk_imports/groups/graphql/get_labels_query.rb +++ /dev/null @@ -1,53 +0,0 @@ -# frozen_string_literal: true - -module BulkImports - module Groups - module Graphql - module GetLabelsQuery - extend self - - def to_s - <<-'GRAPHQL' - query ($full_path: ID!, $cursor: String, $per_page: Int) { - group(fullPath: $full_path) { - labels(first: $per_page, after: $cursor, onlyGroupLabels: true) { - page_info: pageInfo { - next_page: endCursor - has_next_page: hasNextPage - } - nodes { - title - description - color - created_at: createdAt - updated_at: updatedAt - } - } - } - } - 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 labels] - 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/boards_pipeline.rb b/lib/bulk_imports/groups/pipelines/boards_pipeline.rb new file mode 100644 index 00000000000..08a0a4abc9f --- /dev/null +++ b/lib/bulk_imports/groups/pipelines/boards_pipeline.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +module BulkImports + module Groups + module Pipelines + class BoardsPipeline + include NdjsonPipeline + + relation_name 'boards' + + extractor ::BulkImports::Common::Extractors::NdjsonExtractor, relation: relation + end + end + end +end diff --git a/lib/bulk_imports/groups/pipelines/entity_finisher.rb b/lib/bulk_imports/groups/pipelines/entity_finisher.rb index 1d237bc0f7f..1a709179bf9 100644 --- a/lib/bulk_imports/groups/pipelines/entity_finisher.rb +++ b/lib/bulk_imports/groups/pipelines/entity_finisher.rb @@ -4,31 +4,45 @@ 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 context.entity.finished? + return if entity.finished? || entity.failed? - context.entity.finish! + 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 finished' + message: "Entity #{entity.status_name}" ) end private - attr_reader :context + 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 diff --git a/lib/bulk_imports/groups/pipelines/labels_pipeline.rb b/lib/bulk_imports/groups/pipelines/labels_pipeline.rb index 0dc4a968b84..1dd74c10b65 100644 --- a/lib/bulk_imports/groups/pipelines/labels_pipeline.rb +++ b/lib/bulk_imports/groups/pipelines/labels_pipeline.rb @@ -4,16 +4,11 @@ module BulkImports module Groups module Pipelines class LabelsPipeline - include Pipeline + include NdjsonPipeline - extractor BulkImports::Common::Extractors::GraphqlExtractor, - query: BulkImports::Groups::Graphql::GetLabelsQuery + relation_name 'labels' - transformer Common::Transformers::ProhibitedAttributesTransformer - - def load(context, data) - Labels::CreateService.new(data).execute(group: context.group) - end + extractor ::BulkImports::Common::Extractors::NdjsonExtractor, relation: relation end end end diff --git a/lib/bulk_imports/groups/pipelines/milestones_pipeline.rb b/lib/bulk_imports/groups/pipelines/milestones_pipeline.rb index 9b2be30735c..b2bd14952e7 100644 --- a/lib/bulk_imports/groups/pipelines/milestones_pipeline.rb +++ b/lib/bulk_imports/groups/pipelines/milestones_pipeline.rb @@ -4,26 +4,11 @@ module BulkImports module Groups module Pipelines class MilestonesPipeline - include Pipeline + include NdjsonPipeline - extractor BulkImports::Common::Extractors::GraphqlExtractor, - query: BulkImports::Groups::Graphql::GetMilestonesQuery + relation_name 'milestones' - transformer Common::Transformers::ProhibitedAttributesTransformer - - def load(context, data) - return unless data - - raise ::BulkImports::Pipeline::NotAllowedError unless authorized? - - context.group.milestones.create!(data) - end - - private - - def authorized? - context.current_user.can?(:admin_milestone, context.group) - end + extractor ::BulkImports::Common::Extractors::NdjsonExtractor, relation: relation end end end |