2018-11-17 00:37:17 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-04-14 14:57:25 +00:00
|
|
|
module Gitlab
|
2016-04-06 16:12:41 +00:00
|
|
|
module ImportExport
|
2016-06-13 19:18:26 +00:00
|
|
|
class Reader
|
2018-05-03 09:02:26 +00:00
|
|
|
attr_reader :tree, :attributes_finder
|
2016-05-11 15:22:45 +00:00
|
|
|
|
2019-11-11 21:06:20 +00:00
|
|
|
def initialize(shared:, config: ImportExport::Config.new.to_h)
|
|
|
|
@shared = shared
|
|
|
|
@config = config
|
|
|
|
@attributes_finder = Gitlab::ImportExport::AttributesFinder.new(config: @config)
|
2016-04-06 16:12:41 +00:00
|
|
|
end
|
|
|
|
|
2016-06-13 10:32:15 +00:00
|
|
|
# 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.
|
2016-05-06 15:55:06 +00:00
|
|
|
def project_tree
|
2019-11-11 21:06:20 +00:00
|
|
|
tree_by_key(:project)
|
|
|
|
end
|
|
|
|
|
2020-03-17 09:09:20 +00:00
|
|
|
def project_relation_names
|
|
|
|
attributes_finder.find_relations_tree(:project).keys
|
|
|
|
end
|
|
|
|
|
2019-11-11 21:06:20 +00:00
|
|
|
def group_tree
|
|
|
|
tree_by_key(:group)
|
2016-04-12 13:32:25 +00:00
|
|
|
end
|
|
|
|
|
2020-03-17 09:09:20 +00:00
|
|
|
def group_relation_names
|
|
|
|
attributes_finder.find_relations_tree(:group).keys
|
|
|
|
end
|
|
|
|
|
2017-02-01 11:09:02 +00:00
|
|
|
def group_members_tree
|
2019-11-11 21:06:20 +00:00
|
|
|
tree_by_key(:group_members)
|
|
|
|
end
|
|
|
|
|
|
|
|
def tree_by_key(key)
|
|
|
|
attributes_finder.find_root(key)
|
|
|
|
rescue => e
|
|
|
|
@shared.error(e)
|
|
|
|
false
|
2016-04-06 16:12:41 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2016-04-08 13:07:12 +00:00
|
|
|
end
|