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

tree_export_service.rb « bulk_imports « services « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b8e7ac4574b394e5acee77292ea502619dd26d65 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# frozen_string_literal: true

module BulkImports
  class TreeExportService
    def initialize(portable, export_path, relation)
      @portable = portable
      @export_path = export_path
      @relation = relation
      @config = FileTransfer.config_for(portable)
    end

    def execute
      relation_definition = config.tree_relation_definition_for(relation)

      raise BulkImports::Error, 'Unsupported relation export type' unless relation_definition

      serializer.serialize_relation(relation_definition)
    end

    def exported_filename
      "#{relation}.ndjson"
    end

    private

    attr_reader :export_path, :portable, :relation, :config

    # rubocop: disable CodeReuse/Serializer
    def serializer
      ::Gitlab::ImportExport::Json::StreamingSerializer.new(
        portable,
        config.portable_tree,
        json_writer,
        exportable_path: ''
      )
    end
    # rubocop: enable CodeReuse/Serializer

    def json_writer
      ::Gitlab::ImportExport::Json::NdjsonWriter.new(export_path)
    end
  end
end