debian-mirror-gitlab/lib/gitlab/import_export/reader.rb

45 lines
1.1 KiB
Ruby
Raw Normal View History

2019-02-15 15:39:39 +05:30
# frozen_string_literal: true
2016-06-22 15:30:34 +05:30
module Gitlab
module ImportExport
class Reader
2018-06-03 19:52:53 +05:30
attr_reader :tree, :attributes_finder
2016-06-22 15:30:34 +05:30
2019-12-26 22:10:19 +05:30
def initialize(shared:, config: ImportExport::Config.new.to_h)
@shared = shared
@config = config
@attributes_finder = Gitlab::ImportExport::AttributesFinder.new(config: @config)
2016-06-22 15:30:34 +05:30
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
2019-12-26 22:10:19 +05:30
tree_by_key(:project)
end
2020-04-08 14:13:33 +05:30
def project_relation_names
attributes_finder.find_relations_tree(:project).keys
end
2019-12-26 22:10:19 +05:30
def group_tree
tree_by_key(:group)
2016-06-22 15:30:34 +05:30
end
2020-04-08 14:13:33 +05:30
def group_relation_names
attributes_finder.find_relations_tree(:group).keys
end
2017-08-17 22:00:37 +05:30
def group_members_tree
2019-12-26 22:10:19 +05:30
tree_by_key(:group_members)
end
def tree_by_key(key)
attributes_finder.find_root(key)
2021-06-08 01:23:25 +05:30
rescue StandardError => e
2019-12-26 22:10:19 +05:30
@shared.error(e)
false
2016-06-22 15:30:34 +05:30
end
end
end
end