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
0
Merge Requests
0
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
Léo-Paul Géneau
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
Hide 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
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
...
...
app/services/projects/import_export/relation_factory.rb
View file @
267fd01c
...
...
@@ -3,27 +3,21 @@ module Projects
module
RelationFactory
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
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
...
...
fixtures/import_export/project.json
View file @
267fd01c
...
...
@@ -12,12 +12,12 @@
"issues"
:
[
{
"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
,
"author_id"
:
2
,
"project_id"
:
7
,
"created_at"
:
"2016-04-1
2T13:26:48.974
Z"
,
"updated_at"
:
"2016-04-1
2T13:26:55.49
6Z"
,
"project_id"
:
6
,
"created_at"
:
"2016-04-1
3T14:40:32.471
Z"
,
"updated_at"
:
"2016-04-1
3T14:40:38.95
6Z"
,
"position"
:
0
,
"branch_name"
:
null
,
"description"
:
null
,
...
...
@@ -34,8 +34,8 @@
"note"
:
":+1: issue"
,
"noteable_type"
:
"Issue"
,
"author_id"
:
21
,
"created_at"
:
"2016-04-1
2T13:26:55.480
Z"
,
"updated_at"
:
"2016-04-1
2T13:26:55.480
Z"
,
"created_at"
:
"2016-04-1
3T14:40:38.944
Z"
,
"updated_at"
:
"2016-04-1
3T14:40:38.944
Z"
,
"project_id"
:
8
,
"attachment"
:
{
"url"
:
null
...
...
@@ -56,9 +56,9 @@
"id"
:
1
,
"title"
:
"label1"
,
"color"
:
"#990000"
,
"project_id"
:
7
,
"created_at"
:
"2016-04-1
2T13:26:51.027
Z"
,
"updated_at"
:
"2016-04-1
2T13:26:53.799
Z"
,
"project_id"
:
6
,
"created_at"
:
"2016-04-1
3T14:40:34.704
Z"
,
"updated_at"
:
"2016-04-1
3T14:40:36.891
Z"
,
"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-1
2T13:26:53.993
Z"
,
"updated_at"
:
"2016-04-1
2T13:26:53.993
Z"
,
"created_at"
:
"2016-04-1
3T14:40:37.901
Z"
,
"updated_at"
:
"2016-04-1
3T14:40:37.901
Z"
,
"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-1
2T13:26:51.821
Z"
,
"updated_at"
:
"2016-04-1
2T13:26:53.811
Z"
,
"file_name"
:
"
thomas_marquardt
"
,
"project_id"
:
6
,
"created_at"
:
"2016-04-1
3T14:40:35.603
Z"
,
"updated_at"
:
"2016-04-1
3T14:40:36.903
Z"
,
"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-1
2T13:26:52.35
3Z"
,
"updated_at"
:
"2016-04-1
2T13:26:53.82
3Z"
"project_id"
:
6
,
"created_at"
:
"2016-04-1
3T14:40:36.22
3Z"
,
"updated_at"
:
"2016-04-1
3T14:40:36.91
3Z"
}
],
"events"
:
[
...
...
@@ -106,9 +106,9 @@
"target_id"
:
null
,
"title"
:
null
,
"data"
:
null
,
"project_id"
:
7
,
"created_at"
:
"2016-04-1
2T13:26:57.139
Z"
,
"updated_at"
:
"2016-04-1
2T13:26:57.139
Z"
,
"project_id"
:
6
,
"created_at"
:
"2016-04-1
3T14:40:40.122
Z"
,
"updated_at"
:
"2016-04-1
3T14:40:40.122
Z"
,
"action"
:
8
,
"author_id"
:
1
}
...
...
@@ -118,19 +118,19 @@
"id"
:
1
,
"user"
:
{
"id"
:
1
,
"email"
:
"
maybell_auer@gleasonolson.com
"
,
"created_at"
:
"2016-04-1
2T13:26:47.499
Z"
,
"updated_at"
:
"2016-04-1
2T13:26:47.499
Z"
,
"name"
:
"
Charles Nitzsche
"
,
"email"
:
"
norval.gulgowski@schambergerboyle.co.uk
"
,
"created_at"
:
"2016-04-1
3T14:40:30.963
Z"
,
"updated_at"
:
"2016-04-1
3T14:40:30.963
Z"
,
"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.zieme
1"
,
"username"
:
"
vance.turner
1"
,
"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-1
2T13:26:49.813
Z"
,
"updated_at"
:
"2016-04-1
2T13:26:56.806
Z"
,
"title"
:
"
Dignissimos officia sit aut id dolor iure voluptatem expedita
."
,
"created_at"
:
"2016-04-1
3T14:40:33.381
Z"
,
"updated_at"
:
"2016-04-1
3T14:40:39.850
Z"
,
"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-1
2T13:26:49.896
Z"
,
"updated_at"
:
"2016-04-1
2T13:26:50.189
Z"
,
"created_at"
:
"2016-04-1
3T14:40:33.474
Z"
,
"updated_at"
:
"2016-04-1
3T14:40:33.834
Z"
,
"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-1
2T13:26:56.790
Z"
,
"updated_at"
:
"2016-04-1
2T13:26:56.790
Z"
,
"created_at"
:
"2016-04-1
3T14:40:39.832
Z"
,
"updated_at"
:
"2016-04-1
3T14:40:39.832
Z"
,
"project_id"
:
9
,
"attachment"
:
{
"url"
:
null
...
...
@@ -381,52 +381,54 @@
]
}
],
"c
ommit_statuse
s"
:
[
"c
i_commit
s"
:
[
{
"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
}
]
}
]
}
\ 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