Commit 2dc2ce45 authored by James Lopez's avatar James Lopez

WIP - broken spec and some import stuff so I can create a MR on this.

parent 4b88b4ff
module Projects
module ImportExport
class ExportService < BaseService
def execute(options = {})
@import_path = options[:import_path]
end
private
def restore_project_tree
Projects::ImportExport::ProjectTreeRestorer.new(path: @import_path).restore
end
def restore_repo
end
end
end
end
module Projects
module ImportExport
class ProjectTreeRestorer
attr_reader :full_path
def initialize(path: )
@path = path
end
def restore
json = IO.read(@path)
tree_hash = ActiveSupport::JSON.decode(json)
ImportExport.project_tree.each do |relation|
next if tree_hash[relation.to_s].empty?
tree_hash[relation.to_s] = create_relation(relation, tree_hash[relation.to_s])
end
project = Project.new(tree_hash)
project
end
private
def create_relation(relation, tree_hash)
Projects::ImportExport::RelationFactory.create(
relation_sym: relation, relation_hash: tree_hash[relation.to_s])
end
end
end
end
module Projects
module ImportExport
module RelationFactory
extend self
def create(relation_sym: , relation_hash:)
klass = relation_class(relation_sym)
klass.new(relation_hash)
end
private
def relation_class(relation_sym)
relation_sym.to_s.classify.constantize
end
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
require 'spec_helper'
describe Projects::ImportExport::ProjectTreeRestorer, services: true do
describe :restore do
let(:user) { create(:user) }
let(:project_tree_restorer) { Projects::ImportExport::ProjectTreeRestorer.new(path: "fixtures/import_export/project.json") }
before(:each) do
#allow(project_tree_restorer)
# .to receive(:full_path).and_return("fixtures/import_export/project.json")
end
context 'JSON' do
let(:restored_project_json) do
project_tree_restorer.restore
#project_json(project_tree_restorer.full_path)
end
it 'restores models based on JSON' do
expect(restored_project_json).to be true
end
end
end
def project_json
JSON.parse(IO.read("fixtures/import_export/project.json"))
end
end
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