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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

59 lines
1.3 KiB
Ruby
Raw Normal View History

2019-09-04 21:01:54 +05:30
# frozen_string_literal: true
module Gitlab
module ImportExport
class Config
2019-12-26 22:10:19 +05:30
def initialize(config: Gitlab::ImportExport.config_file)
@config = config
2019-12-04 20:38:33 +05:30
@hash = parse_yaml
@hash.deep_symbolize_keys!
@ee_hash = @hash.delete(:ee) || {}
@hash[:tree] = normalize_tree(@hash[:tree])
@ee_hash[:tree] = normalize_tree(@ee_hash[:tree] || {})
end
2019-09-04 21:01:54 +05:30
# Returns a Hash of the YAML file, including EE specific data if EE is
# used.
def to_h
2019-12-04 20:38:33 +05:30
if merge_ee?
deep_merge(@hash, @ee_hash)
else
@hash
2019-09-04 21:01:54 +05:30
end
end
2019-12-04 20:38:33 +05:30
private
2019-09-04 21:01:54 +05:30
2019-12-04 20:38:33 +05:30
def deep_merge(hash_a, hash_b)
hash_a.deep_merge(hash_b) do |_, this_val, other_val|
this_val.to_a + other_val.to_a
2019-09-04 21:01:54 +05:30
end
end
2019-12-04 20:38:33 +05:30
def normalize_tree(item)
case item
when Array
item.reduce({}) do |hash, subitem|
hash.merge!(normalize_tree(subitem))
end
when Hash
item.transform_values(&method(:normalize_tree))
when Symbol
{ item => {} }
else
raise ArgumentError, "#{item} needs to be Array, Hash, Symbol or NilClass"
2019-09-04 21:01:54 +05:30
end
end
2019-12-04 20:38:33 +05:30
def merge_ee?
2019-09-04 21:01:54 +05:30
Gitlab.ee?
end
def parse_yaml
2019-12-26 22:10:19 +05:30
YAML.load_file(@config)
2019-09-04 21:01:54 +05:30
end
end
end
end