Commit febff153 authored by James Lopez's avatar James Lopez
Browse files

started mapping members

parent c5205c611586
module Projects
module ImportExport
class MembersMapper
def self.map(*args)
new(*args).map
end
def initialize(exported_members:)
@exported_members = exported_members
end
def map
#TODO
end
end
end
end
......@@ -3,7 +3,7 @@ module ImportExport
module ProjectFactory
extend self
def create(project_params:, user:)
def create(project_params:, user:, members:)
project = Project.new(project_params.except('id'))
project.creator = user
check_namespace(project_params['namespace_id'], project, user)
......
......@@ -8,32 +8,42 @@ def initialize(path:, user:)
@user = user
end
#TODO deal with ID issues.
#TODO refactor this method
def restore
json = IO.read(@path)
tree_hash = ActiveSupport::JSON.decode(json)
project = create_project(tree_hash)
ImportExport.project_tree.each do |relation|
next if tree_hash[relation.to_s].empty?
relation_hash = create_relation(relation, tree_hash[relation.to_s], project.id)
@tree_hash = ActiveSupport::JSON.decode(json)
create_relations
end
private
def members
@members ||= Projects::ImportExport::MembersMapper.map(exported_members: @tree_hash.delete('project_members'))
end
def create_relations
(ImportExport.project_tree - [:project_members]).each do |relation|
next if @tree_hash[relation.to_s].empty?
relation_hash = create_relation(relation, @tree_hash[relation.to_s])
project.update_attribute(relation, relation_hash)
end
end
private
def project
@project ||= create_project
end
def create_project(tree_hash)
project_params = tree_hash.reject { |_key, value| value.is_a?(Array) }
project = Projects::ImportExport::ProjectFactory.create(project_params: project_params, user: @user)
def create_project
project_params = @tree_hash.reject { |_key, value| value.is_a?(Array) }
project = Projects::ImportExport::ProjectFactory.create(
project_params: project_params, user: @user, members: members)
project.save
project
end
def create_relation(relation, relation_hash_list, project_id)
def create_relation(relation, relation_hash_list)
relation_hash_list.map do |relation_hash|
Projects::ImportExport::RelationFactory.create(
relation_sym: relation, relation_hash: relation_hash.merge(project_id: project_id))
relation_sym: relation, relation_hash: relation_hash.merge(project_id: project.id), members: members)
end
end
end
......
{"id":14,"name":"searchable_project","path":"gitlabhq","description":null,"issues_enabled":true,"wall_enabled":false,"merge_requests_enabled":true,"wiki_enabled":true,"snippets_enabled":true,"visibility_level":20,"archived":false,"issues":[{"id":2,"title":"Eos ut accusamus provident quis qui.","assignee_id":19,"author_id":20,"project_id":14,"created_at":"2016-03-09T11:41:00.754Z","updated_at":"2016-03-09T11:41:05.728Z","position":0,"branch_name":null,"description":null,"milestone_id":null,"state":"opened","iid":1,"updated_by_id":null}],"merge_requests":[{"id":2,"target_branch":"feature","source_branch":"master","source_project_id":9,"author_id":23,"assignee_id":null,"title":"Eos dolores molestias eum magni ut consequatur deleniti distinctio.","created_at":"2016-03-09T11:41:01.820Z","updated_at":"2016-03-09T11:41:01.820Z","milestone_id":null,"state":"opened","merge_status":"can_be_merged","target_project_id":14,"iid":1,"description":null,"position":0,"locked_at":null,"updated_by_id":null,"merge_error":null,"merge_params":{},"merge_when_build_succeeds":false,"merge_user_id":null,"merge_commit_sha":null}],"labels":[{"id":2,"title":"Bug","color":"#990000","project_id":14,"created_at":"2016-03-09T11:41:02.959Z","updated_at":"2016-03-09T11:41:05.750Z","template":false,"description":null}],"milestones":[{"id":2,"title":"Milestone v1.2","project_id":14,"description":null,"due_date":null,"created_at":"2016-03-09T11:41:05.846Z","updated_at":"2016-03-09T11:41:05.846Z","state":"active","iid":1}],"snippets":[{"id":2,"title":"Unde adipisci molestiae modi quisquam qui itaque ut aut.","content":"Temporibus qui nisi ipsam maiores voluptatum.","author_id":30,"project_id":14,"created_at":"2016-03-09T11:41:03.720Z","updated_at":"2016-03-09T11:41:05.763Z","file_name":"sarah","expires_at":null,"visibility_level":0}],"releases":[{"id":2,"tag":"v1.1.0","description":"Awesome release","project_id":14,"created_at":"2016-03-09T11:41:04.342Z","updated_at":"2016-03-09T11:41:05.776Z"}],"events":[{"id":2,"target_type":null,"target_id":null,"title":null,"data":null,"project_id":14,"created_at":"2016-03-09T11:41:05.998Z","updated_at":"2016-03-09T11:41:05.998Z","action":8,"author_id":19}],"commit_statuses":[{"id":2,"project_id":null,"status":"success","finished_at":"2016-01-26T07:23:42.000Z","trace":null,"created_at":"2016-03-09T11:41:05.011Z","updated_at":"2016-03-09T11:41:05.801Z","started_at":"2016-01-26T07:21:42.000Z","runner_id":null,"coverage":null,"commit_id":2,"commands":null,"job_id":null,"name":"default","deploy":false,"options":null,"allow_failure":false,"stage":null,"trigger_request_id":null,"stage_idx":null,"tag":null,"ref":null,"user_id":null,"target_url":null,"description":"commit status","artifacts_file":null,"gl_project_id":14,"artifacts_metadata":null,"erased_by_id":null,"erased_at":null}]}
\ No newline at end of file
{"name":"searchable_project","path":"gitlabhq","description":null,"issues_enabled":true,"wall_enabled":false,"merge_requests_enabled":true,"wiki_enabled":true,"snippets_enabled":true,"visibility_level":20,"archived":false,"issues":[{"id":2,"title":"Culpa dolores et nostrum magni quo.","assignee_id":19,"author_id":20,"project_id":14,"created_at":"2016-03-10T15:54:30.960Z","updated_at":"2016-03-10T15:54:36.624Z","position":0,"branch_name":null,"description":null,"milestone_id":null,"state":"opened","iid":1,"updated_by_id":null}],"merge_requests":[{"id":2,"target_branch":"feature","source_branch":"master","source_project_id":9,"author_id":23,"assignee_id":null,"title":"Distinctio voluptas qui suscipit asperiores.","created_at":"2016-03-10T15:54:31.921Z","updated_at":"2016-03-10T15:54:31.921Z","milestone_id":null,"state":"opened","merge_status":"can_be_merged","target_project_id":14,"iid":1,"description":null,"position":0,"locked_at":null,"updated_by_id":null,"merge_error":null,"merge_params":{},"merge_when_build_succeeds":false,"merge_user_id":null,"merge_commit_sha":null}],"labels":[{"id":2,"title":"Bug","color":"#990000","project_id":14,"created_at":"2016-03-10T15:54:33.128Z","updated_at":"2016-03-10T15:54:36.645Z","template":false,"description":null}],"milestones":[{"id":2,"title":"Milestone v1.2","project_id":14,"description":null,"due_date":null,"created_at":"2016-03-10T15:54:36.756Z","updated_at":"2016-03-10T15:54:36.756Z","state":"active","iid":1}],"snippets":[{"id":2,"title":"In voluptatibus possimus fugiat qui.","content":"Qui exercitationem culpa in dolore ab.","author_id":30,"project_id":14,"created_at":"2016-03-10T15:54:34.253Z","updated_at":"2016-03-10T15:54:36.658Z","file_name":"patrick","expires_at":null,"visibility_level":0}],"releases":[{"id":2,"tag":"v1.1.0","description":"Awesome release","project_id":14,"created_at":"2016-03-10T15:54:35.211Z","updated_at":"2016-03-10T15:54:36.671Z"}],"events":[{"id":2,"target_type":null,"target_id":null,"title":null,"data":null,"project_id":14,"created_at":"2016-03-10T15:54:36.906Z","updated_at":"2016-03-10T15:54:36.906Z","action":8,"author_id":19}],"commit_statuses":[{"id":2,"project_id":null,"status":"success","finished_at":"2016-01-26T07:23:42.000Z","trace":null,"created_at":"2016-03-10T15:54:35.937Z","updated_at":"2016-03-10T15:54:36.699Z","started_at":"2016-01-26T07:21:42.000Z","runner_id":null,"coverage":null,"commit_id":2,"commands":null,"job_id":null,"name":"default","deploy":false,"options":null,"allow_failure":false,"stage":null,"trigger_request_id":null,"stage_idx":null,"tag":null,"ref":null,"user_id":null,"target_url":null,"description":"commit status","artifacts_file":null,"gl_project_id":14,"artifacts_metadata":null,"erased_by_id":null,"erased_at":null}]}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment