2018-11-16 19:37:17 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-04-14 10:57:25 -04:00
|
|
|
module Gitlab
|
2016-04-06 12:12:41 -04:00
|
|
|
module ImportExport
|
2016-06-13 15:18:26 -04:00
|
|
|
class Reader
|
2018-05-03 05:02:26 -04:00
|
|
|
attr_reader :tree, :attributes_finder
|
2016-05-11 11:22:45 -04:00
|
|
|
|
2019-11-11 16:06:20 -05: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 12:12:41 -04:00
|
|
|
end
|
|
|
|
|
2016-06-13 06:32:15 -04: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 11:55:06 -04:00
|
|
|
def project_tree
|
2019-11-11 16:06:20 -05:00
|
|
|
tree_by_key(:project)
|
|
|
|
end
|
|
|
|
|
2020-03-17 05:09:20 -04:00
|
|
|
def project_relation_names
|
|
|
|
attributes_finder.find_relations_tree(:project).keys
|
|
|
|
end
|
|
|
|
|
2019-11-11 16:06:20 -05:00
|
|
|
def group_tree
|
|
|
|
tree_by_key(:group)
|
2016-04-12 09:32:25 -04:00
|
|
|
end
|
|
|
|
|
2020-03-17 05:09:20 -04:00
|
|
|
def group_relation_names
|
|
|
|
attributes_finder.find_relations_tree(:group).keys
|
|
|
|
end
|
|
|
|
|
2017-02-01 06:09:02 -05:00
|
|
|
def group_members_tree
|
2019-11-11 16:06:20 -05: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 12:12:41 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2016-04-08 09:07:12 -04:00
|
|
|
end
|