fixed import and spec is now passing!
This commit is contained in:
parent
36ba23d131
commit
267fd01ce8
3 changed files with 99 additions and 95 deletions
|
@ -25,14 +25,13 @@ module Projects
|
|||
def create_relations(relation_list = default_relation_list, tree_hash = @tree_hash)
|
||||
saved = []
|
||||
relation_list.each do |relation|
|
||||
next if !relation.is_a?(Hash) && tree_hash[relation.to_s].blank?
|
||||
if relation.is_a?(Hash)
|
||||
create_sub_relations(relation, tree_hash)
|
||||
end
|
||||
relation_key = relation.is_a?(Hash) ? relation.keys.first : relation
|
||||
relation_hash = create_relation(relation_key, tree_hash[relation_key.to_s])
|
||||
saved << project.update_attribute(relation_key, relation_hash)
|
||||
# FIXME
|
||||
# next if tree_hash[relation.to_s].blank?
|
||||
end
|
||||
saved.all?
|
||||
end
|
||||
|
|
|
@ -3,27 +3,21 @@ module Projects
|
|||
module RelationFactory
|
||||
extend self
|
||||
|
||||
OVERRIDES = { snippets: :project_snippets, commit: 'Ci::Commit' }.freeze
|
||||
OVERRIDES = { snippets: :project_snippets, ci_commits: 'Ci::Commit', statuses: 'commit_status' }.freeze
|
||||
USER_REFERENCES = %w(author_id assignee_id updated_by_id).freeze
|
||||
|
||||
def create(relation_sym:, relation_hash:, members_map:)
|
||||
relation_sym = parse_relation_sym(relation_sym)
|
||||
klass = parse_relation(relation_hash, relation_sym)
|
||||
|
||||
handle_merge_requests(relation_hash) if relation_sym == :merge_requests
|
||||
update_user_references(relation_hash, members_map)
|
||||
update_project_references(relation_hash, klass)
|
||||
|
||||
imported_object(klass, relation_hash)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def handle_merge_requests(relation_hash)
|
||||
relation_hash['target_project_id'] = relation_hash.delete('project_id')
|
||||
relation_hash['source_project_id'] = -1
|
||||
end
|
||||
|
||||
#TODO nice to have, optimize this to only get called for specific models
|
||||
def update_user_references(relation_hash, members_map)
|
||||
USER_REFERENCES.each do |reference|
|
||||
if relation_hash[reference]
|
||||
|
@ -32,6 +26,16 @@ module Projects
|
|||
end
|
||||
end
|
||||
|
||||
def update_project_references(relation_hash, klass)
|
||||
project_id = relation_hash.delete('project_id')
|
||||
|
||||
# project_id may not be part of the export, but we always need to populate it if required.
|
||||
relation_hash['project_id'] = project_id if klass.column_names.include?('project_id')
|
||||
relation_hash['gl_project_id'] = project_id if relation_hash ['gl_project_id']
|
||||
relation_hash['target_project_id'] = project_id if relation_hash['target_project_id']
|
||||
relation_hash['source_project_id'] = -1 if relation_hash['source_project_id']
|
||||
end
|
||||
|
||||
def relation_class(relation_sym)
|
||||
relation_sym.to_s.classify.constantize
|
||||
end
|
||||
|
@ -49,7 +53,6 @@ module Projects
|
|||
def parse_relation(relation_hash, relation_sym)
|
||||
klass = relation_class(relation_sym)
|
||||
relation_hash.delete('id')
|
||||
relation_hash.delete('project_id') unless klass.column_names.include?('project_id')
|
||||
klass
|
||||
end
|
||||
end
|
||||
|
|
|
@ -12,12 +12,12 @@
|
|||
"issues": [
|
||||
{
|
||||
"id": 1,
|
||||
"title": "Ad est est quia inventore eius suscipit molestiae.",
|
||||
"title": "Debitis vero omnis cum accusamus nihil rerum cupiditate.",
|
||||
"assignee_id": 1,
|
||||
"author_id": 2,
|
||||
"project_id": 7,
|
||||
"created_at": "2016-04-12T13:26:48.974Z",
|
||||
"updated_at": "2016-04-12T13:26:55.496Z",
|
||||
"project_id": 6,
|
||||
"created_at": "2016-04-13T14:40:32.471Z",
|
||||
"updated_at": "2016-04-13T14:40:38.956Z",
|
||||
"position": 0,
|
||||
"branch_name": null,
|
||||
"description": null,
|
||||
|
@ -34,8 +34,8 @@
|
|||
"note": ":+1: issue",
|
||||
"noteable_type": "Issue",
|
||||
"author_id": 21,
|
||||
"created_at": "2016-04-12T13:26:55.480Z",
|
||||
"updated_at": "2016-04-12T13:26:55.480Z",
|
||||
"created_at": "2016-04-13T14:40:38.944Z",
|
||||
"updated_at": "2016-04-13T14:40:38.944Z",
|
||||
"project_id": 8,
|
||||
"attachment": {
|
||||
"url": null
|
||||
|
@ -56,9 +56,9 @@
|
|||
"id": 1,
|
||||
"title": "label1",
|
||||
"color": "#990000",
|
||||
"project_id": 7,
|
||||
"created_at": "2016-04-12T13:26:51.027Z",
|
||||
"updated_at": "2016-04-12T13:26:53.799Z",
|
||||
"project_id": 6,
|
||||
"created_at": "2016-04-13T14:40:34.704Z",
|
||||
"updated_at": "2016-04-13T14:40:36.891Z",
|
||||
"template": false,
|
||||
"description": null
|
||||
}
|
||||
|
@ -67,11 +67,11 @@
|
|||
{
|
||||
"id": 1,
|
||||
"title": "Milestone v1.2",
|
||||
"project_id": 7,
|
||||
"project_id": 6,
|
||||
"description": null,
|
||||
"due_date": null,
|
||||
"created_at": "2016-04-12T13:26:53.993Z",
|
||||
"updated_at": "2016-04-12T13:26:53.993Z",
|
||||
"created_at": "2016-04-13T14:40:37.901Z",
|
||||
"updated_at": "2016-04-13T14:40:37.901Z",
|
||||
"state": "active",
|
||||
"iid": 1
|
||||
}
|
||||
|
@ -79,13 +79,13 @@
|
|||
"snippets": [
|
||||
{
|
||||
"id": 1,
|
||||
"title": "Possimus harum est mollitia fugiat in.",
|
||||
"content": "Itaque ipsum culpa quibusdam mollitia.",
|
||||
"title": "Illo ipsa maxime magni aut.",
|
||||
"content": "Excepturi delectus ut harum est molestiae dolor.",
|
||||
"author_id": 10,
|
||||
"project_id": 7,
|
||||
"created_at": "2016-04-12T13:26:51.821Z",
|
||||
"updated_at": "2016-04-12T13:26:53.811Z",
|
||||
"file_name": "thomas_marquardt",
|
||||
"project_id": 6,
|
||||
"created_at": "2016-04-13T14:40:35.603Z",
|
||||
"updated_at": "2016-04-13T14:40:36.903Z",
|
||||
"file_name": "daphne.mraz",
|
||||
"visibility_level": 0
|
||||
}
|
||||
],
|
||||
|
@ -94,9 +94,9 @@
|
|||
"id": 1,
|
||||
"tag": "v1.1.0",
|
||||
"description": "Awesome release",
|
||||
"project_id": 7,
|
||||
"created_at": "2016-04-12T13:26:52.353Z",
|
||||
"updated_at": "2016-04-12T13:26:53.823Z"
|
||||
"project_id": 6,
|
||||
"created_at": "2016-04-13T14:40:36.223Z",
|
||||
"updated_at": "2016-04-13T14:40:36.913Z"
|
||||
}
|
||||
],
|
||||
"events": [
|
||||
|
@ -106,9 +106,9 @@
|
|||
"target_id": null,
|
||||
"title": null,
|
||||
"data": null,
|
||||
"project_id": 7,
|
||||
"created_at": "2016-04-12T13:26:57.139Z",
|
||||
"updated_at": "2016-04-12T13:26:57.139Z",
|
||||
"project_id": 6,
|
||||
"created_at": "2016-04-13T14:40:40.122Z",
|
||||
"updated_at": "2016-04-13T14:40:40.122Z",
|
||||
"action": 8,
|
||||
"author_id": 1
|
||||
}
|
||||
|
@ -118,19 +118,19 @@
|
|||
"id": 1,
|
||||
"user": {
|
||||
"id": 1,
|
||||
"email": "maybell_auer@gleasonolson.com",
|
||||
"created_at": "2016-04-12T13:26:47.499Z",
|
||||
"updated_at": "2016-04-12T13:26:47.499Z",
|
||||
"name": "Charles Nitzsche",
|
||||
"email": "norval.gulgowski@schambergerboyle.co.uk",
|
||||
"created_at": "2016-04-13T14:40:30.963Z",
|
||||
"updated_at": "2016-04-13T14:40:30.963Z",
|
||||
"name": "Jalon Cormier DVM",
|
||||
"admin": false,
|
||||
"projects_limit": 42,
|
||||
"skype": "",
|
||||
"linkedin": "",
|
||||
"twitter": "",
|
||||
"authentication_token": "nCBdoTPWP-5adipsFwEq",
|
||||
"authentication_token": "tt-mPSZFvRBu8QzkW1Ss",
|
||||
"theme_id": 2,
|
||||
"bio": null,
|
||||
"username": "koby.zieme1",
|
||||
"username": "vance.turner1",
|
||||
"can_create_group": true,
|
||||
"can_create_team": false,
|
||||
"state": "active",
|
||||
|
@ -144,7 +144,7 @@
|
|||
},
|
||||
"hide_no_ssh_key": false,
|
||||
"website_url": "",
|
||||
"notification_email": "maybell_auer@gleasonolson.com",
|
||||
"notification_email": "norval.gulgowski@schambergerboyle.co.uk",
|
||||
"hide_no_password": false,
|
||||
"password_automatically_set": false,
|
||||
"location": null,
|
||||
|
@ -173,13 +173,13 @@
|
|||
"source_project_id": 2,
|
||||
"author_id": 5,
|
||||
"assignee_id": null,
|
||||
"title": "Natus vel molestiae ab et dolorem odit ut.",
|
||||
"created_at": "2016-04-12T13:26:49.813Z",
|
||||
"updated_at": "2016-04-12T13:26:56.806Z",
|
||||
"title": "Dignissimos officia sit aut id dolor iure voluptatem expedita.",
|
||||
"created_at": "2016-04-13T14:40:33.381Z",
|
||||
"updated_at": "2016-04-13T14:40:39.850Z",
|
||||
"milestone_id": null,
|
||||
"state": "opened",
|
||||
"merge_status": "can_be_merged",
|
||||
"target_project_id": 7,
|
||||
"target_project_id": 6,
|
||||
"iid": 1,
|
||||
"description": null,
|
||||
"position": 0,
|
||||
|
@ -353,8 +353,8 @@
|
|||
}
|
||||
],
|
||||
"merge_request_id": 1,
|
||||
"created_at": "2016-04-12T13:26:49.896Z",
|
||||
"updated_at": "2016-04-12T13:26:50.189Z",
|
||||
"created_at": "2016-04-13T14:40:33.474Z",
|
||||
"updated_at": "2016-04-13T14:40:33.834Z",
|
||||
"base_commit_sha": "ae73cb07c9eeaf35924a10f713b364d32b2dd34f",
|
||||
"real_size": "8"
|
||||
},
|
||||
|
@ -364,8 +364,8 @@
|
|||
"note": ":+1: merge_request",
|
||||
"noteable_type": "MergeRequest",
|
||||
"author_id": 24,
|
||||
"created_at": "2016-04-12T13:26:56.790Z",
|
||||
"updated_at": "2016-04-12T13:26:56.790Z",
|
||||
"created_at": "2016-04-13T14:40:39.832Z",
|
||||
"updated_at": "2016-04-13T14:40:39.832Z",
|
||||
"project_id": 9,
|
||||
"attachment": {
|
||||
"url": null
|
||||
|
@ -381,52 +381,54 @@
|
|||
]
|
||||
}
|
||||
],
|
||||
"commit_statuses": [
|
||||
"ci_commits": [
|
||||
{
|
||||
"id": 1,
|
||||
"project_id": null,
|
||||
"status": "success",
|
||||
"finished_at": "2016-01-26T07:23:42.000Z",
|
||||
"trace": null,
|
||||
"created_at": "2016-04-12T13:26:53.034Z",
|
||||
"updated_at": "2016-04-12T13:26:53.850Z",
|
||||
"started_at": "2016-01-26T07:21:42.000Z",
|
||||
"runner_id": null,
|
||||
"coverage": null,
|
||||
"commit_id": 1,
|
||||
"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": 7,
|
||||
"artifacts_metadata": null,
|
||||
"erased_by_id": null,
|
||||
"erased_at": null,
|
||||
"commit": {
|
||||
"id": 1,
|
||||
"project_id": 6,
|
||||
"ref": null,
|
||||
"sha": "97de212e80737a608d939f648d959671fb0a0142",
|
||||
"before_sha": null,
|
||||
"push_data": null,
|
||||
"created_at": "2016-04-12T13:26:53.010Z",
|
||||
"updated_at": "2016-04-12T13:26:53.010Z",
|
||||
"tag": false,
|
||||
"yaml_errors": null,
|
||||
"committed_at": null,
|
||||
"gl_project_id": 6
|
||||
}
|
||||
"id": 2,
|
||||
"project_id": 6,
|
||||
"ref": "master",
|
||||
"sha": "5937ac0a7beb003549fc5fd26fc247adbce4a52e",
|
||||
"before_sha": null,
|
||||
"push_data": null,
|
||||
"created_at": "2016-04-13T14:40:37.759Z",
|
||||
"updated_at": "2016-04-13T14:40:37.759Z",
|
||||
"tag": false,
|
||||
"yaml_errors": null,
|
||||
"committed_at": null,
|
||||
"gl_project_id": 6,
|
||||
"statuses": [
|
||||
{
|
||||
"id": 1,
|
||||
"project_id": null,
|
||||
"status": "success",
|
||||
"finished_at": "2016-01-26T07:23:42.000Z",
|
||||
"trace": null,
|
||||
"created_at": "2016-04-13T14:40:37.717Z",
|
||||
"updated_at": "2016-04-13T14:40:37.771Z",
|
||||
"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": 7,
|
||||
"artifacts_metadata": null,
|
||||
"erased_by_id": null,
|
||||
"erased_at": null
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
Loading…
Reference in a new issue