Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
267fd01c
Commit
267fd01c
authored
Apr 13, 2016
by
James Lopez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed import and spec is now passing!
parent
36ba23d1
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
99 additions
and
95 deletions
+99
-95
app/services/projects/import_export/project_tree_restorer.rb
app/services/projects/import_export/project_tree_restorer.rb
+1
-2
app/services/projects/import_export/relation_factory.rb
app/services/projects/import_export/relation_factory.rb
+12
-9
fixtures/import_export/project.json
fixtures/import_export/project.json
+86
-84
No files found.
app/services/projects/import_export/project_tree_restorer.rb
View file @
267fd01c
...
@@ -25,14 +25,13 @@ module Projects
...
@@ -25,14 +25,13 @@ module Projects
def
create_relations
(
relation_list
=
default_relation_list
,
tree_hash
=
@tree_hash
)
def
create_relations
(
relation_list
=
default_relation_list
,
tree_hash
=
@tree_hash
)
saved
=
[]
saved
=
[]
relation_list
.
each
do
|
relation
|
relation_list
.
each
do
|
relation
|
next
if
!
relation
.
is_a?
(
Hash
)
&&
tree_hash
[
relation
.
to_s
].
blank?
if
relation
.
is_a?
(
Hash
)
if
relation
.
is_a?
(
Hash
)
create_sub_relations
(
relation
,
tree_hash
)
create_sub_relations
(
relation
,
tree_hash
)
end
end
relation_key
=
relation
.
is_a?
(
Hash
)
?
relation
.
keys
.
first
:
relation
relation_key
=
relation
.
is_a?
(
Hash
)
?
relation
.
keys
.
first
:
relation
relation_hash
=
create_relation
(
relation_key
,
tree_hash
[
relation_key
.
to_s
])
relation_hash
=
create_relation
(
relation_key
,
tree_hash
[
relation_key
.
to_s
])
saved
<<
project
.
update_attribute
(
relation_key
,
relation_hash
)
saved
<<
project
.
update_attribute
(
relation_key
,
relation_hash
)
# FIXME
# next if tree_hash[relation.to_s].blank?
end
end
saved
.
all?
saved
.
all?
end
end
...
...
app/services/projects/import_export/relation_factory.rb
View file @
267fd01c
...
@@ -3,27 +3,21 @@ module Projects
...
@@ -3,27 +3,21 @@ module Projects
module
RelationFactory
module
RelationFactory
extend
self
extend
self
OVERRIDES
=
{
snippets: :project_snippets
,
c
ommit:
'Ci::Commit
'
}.
freeze
OVERRIDES
=
{
snippets: :project_snippets
,
c
i_commits:
'Ci::Commit'
,
statuses:
'commit_status
'
}.
freeze
USER_REFERENCES
=
%w(author_id assignee_id updated_by_id)
.
freeze
USER_REFERENCES
=
%w(author_id assignee_id updated_by_id)
.
freeze
def
create
(
relation_sym
:,
relation_hash
:,
members_map
:)
def
create
(
relation_sym
:,
relation_hash
:,
members_map
:)
relation_sym
=
parse_relation_sym
(
relation_sym
)
relation_sym
=
parse_relation_sym
(
relation_sym
)
klass
=
parse_relation
(
relation_hash
,
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_user_references
(
relation_hash
,
members_map
)
update_project_references
(
relation_hash
,
klass
)
imported_object
(
klass
,
relation_hash
)
imported_object
(
klass
,
relation_hash
)
end
end
private
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
)
def
update_user_references
(
relation_hash
,
members_map
)
USER_REFERENCES
.
each
do
|
reference
|
USER_REFERENCES
.
each
do
|
reference
|
if
relation_hash
[
reference
]
if
relation_hash
[
reference
]
...
@@ -32,6 +26,16 @@ module Projects
...
@@ -32,6 +26,16 @@ module Projects
end
end
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
)
def
relation_class
(
relation_sym
)
relation_sym
.
to_s
.
classify
.
constantize
relation_sym
.
to_s
.
classify
.
constantize
end
end
...
@@ -49,7 +53,6 @@ module Projects
...
@@ -49,7 +53,6 @@ module Projects
def
parse_relation
(
relation_hash
,
relation_sym
)
def
parse_relation
(
relation_hash
,
relation_sym
)
klass
=
relation_class
(
relation_sym
)
klass
=
relation_class
(
relation_sym
)
relation_hash
.
delete
(
'id'
)
relation_hash
.
delete
(
'id'
)
relation_hash
.
delete
(
'project_id'
)
unless
klass
.
column_names
.
include?
(
'project_id'
)
klass
klass
end
end
end
end
...
...
fixtures/import_export/project.json
View file @
267fd01c
...
@@ -12,12 +12,12 @@
...
@@ -12,12 +12,12 @@
"issues"
:
[
"issues"
:
[
{
{
"id"
:
1
,
"id"
:
1
,
"title"
:
"
Ad est est quia inventore eius suscipit molestia
e."
,
"title"
:
"
Debitis vero omnis cum accusamus nihil rerum cupiditat
e."
,
"assignee_id"
:
1
,
"assignee_id"
:
1
,
"author_id"
:
2
,
"author_id"
:
2
,
"project_id"
:
7
,
"project_id"
:
6
,
"created_at"
:
"2016-04-1
2T13:26:48.974
Z"
,
"created_at"
:
"2016-04-1
3T14:40:32.471
Z"
,
"updated_at"
:
"2016-04-1
2T13:26:55.49
6Z"
,
"updated_at"
:
"2016-04-1
3T14:40:38.95
6Z"
,
"position"
:
0
,
"position"
:
0
,
"branch_name"
:
null
,
"branch_name"
:
null
,
"description"
:
null
,
"description"
:
null
,
...
@@ -34,8 +34,8 @@
...
@@ -34,8 +34,8 @@
"note"
:
":+1: issue"
,
"note"
:
":+1: issue"
,
"noteable_type"
:
"Issue"
,
"noteable_type"
:
"Issue"
,
"author_id"
:
21
,
"author_id"
:
21
,
"created_at"
:
"2016-04-1
2T13:26:55.480
Z"
,
"created_at"
:
"2016-04-1
3T14:40:38.944
Z"
,
"updated_at"
:
"2016-04-1
2T13:26:55.480
Z"
,
"updated_at"
:
"2016-04-1
3T14:40:38.944
Z"
,
"project_id"
:
8
,
"project_id"
:
8
,
"attachment"
:
{
"attachment"
:
{
"url"
:
null
"url"
:
null
...
@@ -56,9 +56,9 @@
...
@@ -56,9 +56,9 @@
"id"
:
1
,
"id"
:
1
,
"title"
:
"label1"
,
"title"
:
"label1"
,
"color"
:
"#990000"
,
"color"
:
"#990000"
,
"project_id"
:
7
,
"project_id"
:
6
,
"created_at"
:
"2016-04-1
2T13:26:51.027
Z"
,
"created_at"
:
"2016-04-1
3T14:40:34.704
Z"
,
"updated_at"
:
"2016-04-1
2T13:26:53.799
Z"
,
"updated_at"
:
"2016-04-1
3T14:40:36.891
Z"
,
"template"
:
false
,
"template"
:
false
,
"description"
:
null
"description"
:
null
}
}
...
@@ -67,11 +67,11 @@
...
@@ -67,11 +67,11 @@
{
{
"id"
:
1
,
"id"
:
1
,
"title"
:
"Milestone v1.2"
,
"title"
:
"Milestone v1.2"
,
"project_id"
:
7
,
"project_id"
:
6
,
"description"
:
null
,
"description"
:
null
,
"due_date"
:
null
,
"due_date"
:
null
,
"created_at"
:
"2016-04-1
2T13:26:53.993
Z"
,
"created_at"
:
"2016-04-1
3T14:40:37.901
Z"
,
"updated_at"
:
"2016-04-1
2T13:26:53.993
Z"
,
"updated_at"
:
"2016-04-1
3T14:40:37.901
Z"
,
"state"
:
"active"
,
"state"
:
"active"
,
"iid"
:
1
"iid"
:
1
}
}
...
@@ -79,13 +79,13 @@
...
@@ -79,13 +79,13 @@
"snippets"
:
[
"snippets"
:
[
{
{
"id"
:
1
,
"id"
:
1
,
"title"
:
"
Possimus harum est mollitia fugiat in
."
,
"title"
:
"
Illo ipsa maxime magni aut
."
,
"content"
:
"
Itaque ipsum culpa quibusdam mollitia
."
,
"content"
:
"
Excepturi delectus ut harum est molestiae dolor
."
,
"author_id"
:
10
,
"author_id"
:
10
,
"project_id"
:
7
,
"project_id"
:
6
,
"created_at"
:
"2016-04-1
2T13:26:51.821
Z"
,
"created_at"
:
"2016-04-1
3T14:40:35.603
Z"
,
"updated_at"
:
"2016-04-1
2T13:26:53.811
Z"
,
"updated_at"
:
"2016-04-1
3T14:40:36.903
Z"
,
"file_name"
:
"
thomas_marquardt
"
,
"file_name"
:
"
daphne.mraz
"
,
"visibility_level"
:
0
"visibility_level"
:
0
}
}
],
],
...
@@ -94,9 +94,9 @@
...
@@ -94,9 +94,9 @@
"id"
:
1
,
"id"
:
1
,
"tag"
:
"v1.1.0"
,
"tag"
:
"v1.1.0"
,
"description"
:
"Awesome release"
,
"description"
:
"Awesome release"
,
"project_id"
:
7
,
"project_id"
:
6
,
"created_at"
:
"2016-04-1
2T13:26:52.35
3Z"
,
"created_at"
:
"2016-04-1
3T14:40:36.22
3Z"
,
"updated_at"
:
"2016-04-1
2T13:26:53.82
3Z"
"updated_at"
:
"2016-04-1
3T14:40:36.91
3Z"
}
}
],
],
"events"
:
[
"events"
:
[
...
@@ -106,9 +106,9 @@
...
@@ -106,9 +106,9 @@
"target_id"
:
null
,
"target_id"
:
null
,
"title"
:
null
,
"title"
:
null
,
"data"
:
null
,
"data"
:
null
,
"project_id"
:
7
,
"project_id"
:
6
,
"created_at"
:
"2016-04-1
2T13:26:57.139
Z"
,
"created_at"
:
"2016-04-1
3T14:40:40.122
Z"
,
"updated_at"
:
"2016-04-1
2T13:26:57.139
Z"
,
"updated_at"
:
"2016-04-1
3T14:40:40.122
Z"
,
"action"
:
8
,
"action"
:
8
,
"author_id"
:
1
"author_id"
:
1
}
}
...
@@ -118,19 +118,19 @@
...
@@ -118,19 +118,19 @@
"id"
:
1
,
"id"
:
1
,
"user"
:
{
"user"
:
{
"id"
:
1
,
"id"
:
1
,
"email"
:
"
maybell_auer@gleasonolson.com
"
,
"email"
:
"
norval.gulgowski@schambergerboyle.co.uk
"
,
"created_at"
:
"2016-04-1
2T13:26:47.499
Z"
,
"created_at"
:
"2016-04-1
3T14:40:30.963
Z"
,
"updated_at"
:
"2016-04-1
2T13:26:47.499
Z"
,
"updated_at"
:
"2016-04-1
3T14:40:30.963
Z"
,
"name"
:
"
Charles Nitzsche
"
,
"name"
:
"
Jalon Cormier DVM
"
,
"admin"
:
false
,
"admin"
:
false
,
"projects_limit"
:
42
,
"projects_limit"
:
42
,
"skype"
:
""
,
"skype"
:
""
,
"linkedin"
:
""
,
"linkedin"
:
""
,
"twitter"
:
""
,
"twitter"
:
""
,
"authentication_token"
:
"
nCBdoTPWP-5adipsFwEq
"
,
"authentication_token"
:
"
tt-mPSZFvRBu8QzkW1Ss
"
,
"theme_id"
:
2
,
"theme_id"
:
2
,
"bio"
:
null
,
"bio"
:
null
,
"username"
:
"
koby.zieme
1"
,
"username"
:
"
vance.turner
1"
,
"can_create_group"
:
true
,
"can_create_group"
:
true
,
"can_create_team"
:
false
,
"can_create_team"
:
false
,
"state"
:
"active"
,
"state"
:
"active"
,
...
@@ -144,7 +144,7 @@
...
@@ -144,7 +144,7 @@
},
},
"hide_no_ssh_key"
:
false
,
"hide_no_ssh_key"
:
false
,
"website_url"
:
""
,
"website_url"
:
""
,
"notification_email"
:
"
maybell_auer@gleasonolson.com
"
,
"notification_email"
:
"
norval.gulgowski@schambergerboyle.co.uk
"
,
"hide_no_password"
:
false
,
"hide_no_password"
:
false
,
"password_automatically_set"
:
false
,
"password_automatically_set"
:
false
,
"location"
:
null
,
"location"
:
null
,
...
@@ -173,13 +173,13 @@
...
@@ -173,13 +173,13 @@
"source_project_id"
:
2
,
"source_project_id"
:
2
,
"author_id"
:
5
,
"author_id"
:
5
,
"assignee_id"
:
null
,
"assignee_id"
:
null
,
"title"
:
"
Natus vel molestiae ab et dolorem odit ut
."
,
"title"
:
"
Dignissimos officia sit aut id dolor iure voluptatem expedita
."
,
"created_at"
:
"2016-04-1
2T13:26:49.813
Z"
,
"created_at"
:
"2016-04-1
3T14:40:33.381
Z"
,
"updated_at"
:
"2016-04-1
2T13:26:56.806
Z"
,
"updated_at"
:
"2016-04-1
3T14:40:39.850
Z"
,
"milestone_id"
:
null
,
"milestone_id"
:
null
,
"state"
:
"opened"
,
"state"
:
"opened"
,
"merge_status"
:
"can_be_merged"
,
"merge_status"
:
"can_be_merged"
,
"target_project_id"
:
7
,
"target_project_id"
:
6
,
"iid"
:
1
,
"iid"
:
1
,
"description"
:
null
,
"description"
:
null
,
"position"
:
0
,
"position"
:
0
,
...
@@ -353,8 +353,8 @@
...
@@ -353,8 +353,8 @@
}
}
],
],
"merge_request_id"
:
1
,
"merge_request_id"
:
1
,
"created_at"
:
"2016-04-1
2T13:26:49.896
Z"
,
"created_at"
:
"2016-04-1
3T14:40:33.474
Z"
,
"updated_at"
:
"2016-04-1
2T13:26:50.189
Z"
,
"updated_at"
:
"2016-04-1
3T14:40:33.834
Z"
,
"base_commit_sha"
:
"ae73cb07c9eeaf35924a10f713b364d32b2dd34f"
,
"base_commit_sha"
:
"ae73cb07c9eeaf35924a10f713b364d32b2dd34f"
,
"real_size"
:
"8"
"real_size"
:
"8"
},
},
...
@@ -364,8 +364,8 @@
...
@@ -364,8 +364,8 @@
"note"
:
":+1: merge_request"
,
"note"
:
":+1: merge_request"
,
"noteable_type"
:
"MergeRequest"
,
"noteable_type"
:
"MergeRequest"
,
"author_id"
:
24
,
"author_id"
:
24
,
"created_at"
:
"2016-04-1
2T13:26:56.790
Z"
,
"created_at"
:
"2016-04-1
3T14:40:39.832
Z"
,
"updated_at"
:
"2016-04-1
2T13:26:56.790
Z"
,
"updated_at"
:
"2016-04-1
3T14:40:39.832
Z"
,
"project_id"
:
9
,
"project_id"
:
9
,
"attachment"
:
{
"attachment"
:
{
"url"
:
null
"url"
:
null
...
@@ -381,19 +381,33 @@
...
@@ -381,19 +381,33 @@
]
]
}
}
],
],
"commit_statuses"
:
[
"ci_commits"
:
[
{
"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
,
"id"
:
1
,
"project_id"
:
null
,
"project_id"
:
null
,
"status"
:
"success"
,
"status"
:
"success"
,
"finished_at"
:
"2016-01-26T07:23:42.000Z"
,
"finished_at"
:
"2016-01-26T07:23:42.000Z"
,
"trace"
:
null
,
"trace"
:
null
,
"created_at"
:
"2016-04-12T13:26:53.034
Z"
,
"created_at"
:
"2016-04-13T14:40:37.717
Z"
,
"updated_at"
:
"2016-04-12T13:26:53.850
Z"
,
"updated_at"
:
"2016-04-13T14:40:37.771
Z"
,
"started_at"
:
"2016-01-26T07:21:42.000Z"
,
"started_at"
:
"2016-01-26T07:21:42.000Z"
,
"runner_id"
:
null
,
"runner_id"
:
null
,
"coverage"
:
null
,
"coverage"
:
null
,
"commit_id"
:
1
,
"commit_id"
:
2
,
"commands"
:
null
,
"commands"
:
null
,
"job_id"
:
null
,
"job_id"
:
null
,
"name"
:
"default"
,
"name"
:
"default"
,
...
@@ -412,21 +426,9 @@
...
@@ -412,21 +426,9 @@
"gl_project_id"
:
7
,
"gl_project_id"
:
7
,
"artifacts_metadata"
:
null
,
"artifacts_metadata"
:
null
,
"erased_by_id"
:
null
,
"erased_by_id"
:
null
,
"erased_at"
:
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
}
}
]
}
}
]
]
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment