mirror of
https://github.com/wahyd4/gitlabhq.git
synced 2026-08-11 21:56:19 +10:00
Export project functionality This is a MR for the export functionality of https://gitlab.com/gitlab-org/gitlab-ce/issues/3050, which adds the ability to export single projects. - [x] members - DB data - [x] issues - [x] issue comments - [x] merge requests - [x] merge request diff - [x] merge request comments - [x] labels - [x] milestones - [x] snippets - [x] releases - [x] events - [x] commit statuses - [x] CI builds - File system data - [x] Git repository - [x] wiki - [x] uploads - [ ] ~~CI build traces~~ - [ ] ~~CI build artifacts~~ - [ ] ~~LFS objects~~ - DB configuration - [x] services - [x] web hooks - [x] protected branches - [x] deploy keys - [x] CI variables - [x] CI triggers See merge request !3114
48 lines
1.3 KiB
Ruby
48 lines
1.3 KiB
Ruby
module Gitlab
|
|
module ImportExport
|
|
class AttributesFinder
|
|
|
|
def initialize(included_attributes:, excluded_attributes:, methods:)
|
|
@included_attributes = included_attributes || {}
|
|
@excluded_attributes = excluded_attributes || {}
|
|
@methods = methods || {}
|
|
end
|
|
|
|
def find(model_object)
|
|
parsed_hash = find_attributes_only(model_object)
|
|
parsed_hash.empty? ? model_object : { model_object => parsed_hash }
|
|
end
|
|
|
|
def parse(model_object)
|
|
parsed_hash = find_attributes_only(model_object)
|
|
yield parsed_hash unless parsed_hash.empty?
|
|
end
|
|
|
|
def find_included(value)
|
|
key = key_from_hash(value)
|
|
@included_attributes[key].nil? ? {} : { only: @included_attributes[key] }
|
|
end
|
|
|
|
def find_excluded(value)
|
|
key = key_from_hash(value)
|
|
@excluded_attributes[key].nil? ? {} : { except: @excluded_attributes[key] }
|
|
end
|
|
|
|
def find_method(value)
|
|
key = key_from_hash(value)
|
|
@methods[key].nil? ? {} : { methods: @methods[key] }
|
|
end
|
|
|
|
private
|
|
|
|
def find_attributes_only(value)
|
|
find_included(value).merge(find_excluded(value)).merge(find_method(value))
|
|
end
|
|
|
|
def key_from_hash(value)
|
|
value.is_a?(Hash) ? value.keys.first : value
|
|
end
|
|
end
|
|
end
|
|
end
|