summaryrefslogtreecommitdiff
path: root/lib/gitlab/import_export/reader.rb
blob: 8d36d05ca6fc725dfa2271e1a36274fea3a9d104 (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
44
# frozen_string_literal: true

module Gitlab
  module ImportExport
    class Reader
      attr_reader :tree, :attributes_finder

      def initialize(shared:, config: ImportExport::Config.new.to_h)
        @shared            = shared
        @config            = config
        @attributes_finder = Gitlab::ImportExport::AttributesFinder.new(config: @config)
      end

      # Outputs a hash in the format described here: http://api.rubyonrails.org/classes/ActiveModel/Serializers/JSON.html
      # for outputting a project in JSON format, including its relations and sub relations.
      def project_tree
        tree_by_key(:project)
      end

      def project_relation_names
        attributes_finder.find_relations_tree(:project).keys
      end

      def group_tree
        tree_by_key(:group)
      end

      def group_relation_names
        attributes_finder.find_relations_tree(:group).keys
      end

      def group_members_tree
        tree_by_key(:group_members)
      end

      def tree_by_key(key)
        attributes_finder.find_root(key)
      rescue => e
        @shared.error(e)
        false
      end
    end
  end
end