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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
gitlab-ce
Commits
0df21ac7
Commit
0df21ac7
authored
May 18, 2016
by
James Lopez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
revert changes as builds are related to statuses which are already there
parent
4d894a7a
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
23 additions
and
106 deletions
+23
-106
lib/gitlab/import_export/commit_mapper.rb
lib/gitlab/import_export/commit_mapper.rb
+0
-49
lib/gitlab/import_export/project_tree_restorer.rb
lib/gitlab/import_export/project_tree_restorer.rb
+3
-11
lib/gitlab/import_export/relation_factory.rb
lib/gitlab/import_export/relation_factory.rb
+20
-46
No files found.
lib/gitlab/import_export/commit_mapper.rb
deleted
100644 → 0
View file @
4d894a7a
module
Gitlab
module
ImportExport
class
CommitMapper
def
initialize
(
commits
:,
members_map
:,
project_id
:,
relation_factory:
Gitlab
::
ImportExport
::
RelationFactory
,
user_admin
:)
@commits
=
commits
@members_map
=
members_map
@project_id
=
project_id
@relation_factory
=
relation_factory
@user_admin
=
user_admin
end
def
ids_map
@ids_map
||=
map_commits
end
def
map_commits
@id_map
=
Hash
.
new
(
-
1
)
@commits
.
each
do
|
commit_hash
|
@relation_factory
.
update_user_references
(
commit_hash
,
@members_map
)
commit_hash
[
'project_id'
]
=
@project_id
@relation_factory
.
update_project_references
(
commit_hash
,
Ci
::
Commit
)
create_commit_statuses
(
commit_hash
)
create_commit
(
commit_hash
)
end
@id_map
end
def
create_commit
(
commit_hash
)
old_id
=
commit_hash
.
delete
(
'id'
)
commit
=
Ci
::
Commit
.
new
(
commit_hash
)
commit
.
save!
@id_map
[
old_id
]
=
commit
.
id
end
def
create_commit_statuses
(
commit_hash
)
commit_hash
[
'statuses'
].
map!
do
|
status_hash
|
@relation_factory
.
create
(
relation_sym: :statuses
,
relation_hash:
status_hash
.
merge
(
'project_id'
=>
@project_id
,
'commit_id'
=>
nil
),
members_mapper:
@members_map
,
commits_mapper:
nil
,
user_admin:
@user_admin
)
end
end
end
end
end
lib/gitlab/import_export/project_tree_restorer.rb
View file @
0df21ac7
...
@@ -14,7 +14,6 @@ module Gitlab
...
@@ -14,7 +14,6 @@ module Gitlab
json
=
IO
.
read
(
@path
)
json
=
IO
.
read
(
@path
)
@tree_hash
=
ActiveSupport
::
JSON
.
decode
(
json
)
@tree_hash
=
ActiveSupport
::
JSON
.
decode
(
json
)
@project_members
=
@tree_hash
.
delete
(
'project_members'
)
@project_members
=
@tree_hash
.
delete
(
'project_members'
)
@commits
=
@tree_hash
.
delete
(
'ci_commits'
)
create_relations
create_relations
rescue
=>
e
rescue
=>
e
@shared
.
error
(
e
)
@shared
.
error
(
e
)
...
@@ -33,13 +32,6 @@ module Gitlab
...
@@ -33,13 +32,6 @@ module Gitlab
project:
project
)
project:
project
)
end
end
def
commits_mapper
@commits_mapper
||=
Gitlab
::
ImportExport
::
CommitMapper
.
new
(
commits:
@commits
,
members_map:
members_mapper
.
map
,
project_id:
project
.
id
,
user_admin:
@user
.
is_admin?
)
end
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
|
...
@@ -55,7 +47,7 @@ module Gitlab
...
@@ -55,7 +47,7 @@ module Gitlab
def
default_relation_list
def
default_relation_list
Gitlab
::
ImportExport
::
ImportExportReader
.
new
(
shared:
@shared
).
tree
.
reject
do
|
model
|
Gitlab
::
ImportExport
::
ImportExportReader
.
new
(
shared:
@shared
).
tree
.
reject
do
|
model
|
model
.
is_a?
(
Hash
)
&&
(
model
[
:project_members
]
||
model
[
:ci_commits
])
model
.
is_a?
(
Hash
)
&&
model
[
:project_members
]
end
end
end
end
...
@@ -73,6 +65,7 @@ module Gitlab
...
@@ -73,6 +65,7 @@ module Gitlab
relation_key
=
relation
.
keys
.
first
.
to_s
relation_key
=
relation
.
keys
.
first
.
to_s
tree_hash
[
relation_key
].
each
do
|
relation_item
|
tree_hash
[
relation_key
].
each
do
|
relation_item
|
relation
.
values
.
flatten
.
each
do
|
sub_relation
|
relation
.
values
.
flatten
.
each
do
|
sub_relation
|
if
sub_relation
.
is_a?
(
Hash
)
if
sub_relation
.
is_a?
(
Hash
)
relation_hash
=
relation_item
[
sub_relation
.
keys
.
first
.
to_s
]
relation_hash
=
relation_item
[
sub_relation
.
keys
.
first
.
to_s
]
sub_relation
=
sub_relation
.
keys
.
first
sub_relation
=
sub_relation
.
keys
.
first
...
@@ -104,7 +97,6 @@ module Gitlab
...
@@ -104,7 +97,6 @@ module Gitlab
Gitlab
::
ImportExport
::
RelationFactory
.
create
(
relation_sym:
relation
.
to_sym
,
Gitlab
::
ImportExport
::
RelationFactory
.
create
(
relation_sym:
relation
.
to_sym
,
relation_hash:
relation_hash
.
merge
(
'project_id'
=>
project
.
id
),
relation_hash:
relation_hash
.
merge
(
'project_id'
=>
project
.
id
),
members_mapper:
members_mapper
,
members_mapper:
members_mapper
,
commits_mapper:
commits_mapper
,
user_admin:
@user
.
is_admin?
)
user_admin:
@user
.
is_admin?
)
end
end
end
end
...
...
lib/gitlab/import_export/relation_factory.rb
View file @
0df21ac7
...
@@ -3,27 +3,21 @@ module Gitlab
...
@@ -3,27 +3,21 @@ module Gitlab
module
RelationFactory
module
RelationFactory
extend
self
extend
self
OVERRIDES
=
{
snippets: :project_snippets
,
OVERRIDES
=
{
snippets: :project_snippets
,
ci_commits:
'Ci::Commit'
,
statuses:
'commit_status'
}.
freeze
ci_commits:
'Ci::Commit'
,
USER_REFERENCES
=
%w(author_id assignee_id updated_by_id)
.
freeze
statuses:
'commit_status'
,
variables:
'Ci::Variable'
,
def
create
(
relation_sym
:,
relation_hash
:,
members_mapper
:,
user_admin
:)
triggers:
'Ci::Trigger'
,
builds:
'Ci::Build'
,
hooks:
'ProjectHook'
}.
freeze
USER_REFERENCES
=
%w(author_id assignee_id updated_by_id user_id)
.
freeze
def
create
(
relation_sym
:,
relation_hash
:,
members_mapper
:,
commits_mapper
:,
user_admin
:)
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
)
update_missing_author
(
relation_hash
,
members_mapper
,
user_admin
)
if
relation_sym
==
:notes
update_missing_author
(
relation_hash
,
members_mapper
,
user_admin
)
if
relation_sym
==
:notes
update_user_references
(
relation_hash
,
members_mapper
.
map
)
update_user_references
(
relation_hash
,
members_mapper
.
map
)
update_project_references
(
relation_hash
,
klass
)
update_project_references
(
relation_hash
,
klass
)
update_commit_references
(
relation_hash
,
commits_mapper
.
ids_map
)
if
commits_mapper
generate_imported_object
(
klass
,
relation_hash
,
relation_sym
)
imported_object
(
klass
,
relation_hash
)
end
end
private
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
|
...
@@ -33,32 +27,6 @@ module Gitlab
...
@@ -33,32 +27,6 @@ module Gitlab
end
end
end
end
def
update_project_references
(
relation_hash
,
klass
)
project_id
=
relation_hash
.
delete
(
'project_id'
)
if
relation_hash
[
'source_project_id'
]
&&
relation_hash
[
'target_project_id'
]
# If source and target are the same, populate them with the new project ID.
if
relation_hash
[
'target_project_id'
]
==
relation_hash
[
'source_project_id'
]
relation_hash
[
'source_project_id'
]
=
project_id
else
relation_hash
[
'source_project_id'
]
=
-
1
end
end
relation_hash
[
'target_project_id'
]
=
project_id
if
relation_hash
[
'target_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'
]
end
private
def
update_commit_references
(
relation_hash
,
commit_ids_map
)
return
unless
relation_hash
[
'commit_id'
]
old_commit_id
=
relation_hash
[
'commit_id'
]
relation_hash
[
'commit_id'
]
=
commit_ids_map
[
old_commit_id
]
end
def
update_missing_author
(
relation_hash
,
members_map
,
user_admin
)
def
update_missing_author
(
relation_hash
,
members_map
,
user_admin
)
old_author_id
=
relation_hash
[
'author_id'
]
old_author_id
=
relation_hash
[
'author_id'
]
...
@@ -82,15 +50,22 @@ module Gitlab
...
@@ -82,15 +50,22 @@ module Gitlab
"
\n\n
*By
#{
author_name
}
on
#{
timestamp
}
(imported from GitLab project)*"
"
\n\n
*By
#{
author_name
}
on
#{
timestamp
}
(imported from GitLab project)*"
end
end
def
generate_imported_object
(
klass
,
relation_hash
,
relation_sym
)
def
update_project_references
(
relation_hash
,
klass
)
if
relation_sym
==
'Ci::Build'
# call #trace= method after assigning the other attributes
project_id
=
relation_hash
.
delete
(
'project_id'
)
trace
=
relation_hash
.
delete
(
'trace'
)
imported_object
(
klass
,
relation_hash
)
do
|
imported_object
|
if
relation_hash
[
'source_project_id'
]
&&
relation_hash
[
'target_project_id'
]
imported_object
.
trace
=
trace
# If source and target are the same, populate them with the new project ID.
end
if
relation_hash
[
'target_project_id'
]
==
relation_hash
[
'source_project_id'
]
relation_hash
[
'source_project_id'
]
=
project_id
else
else
imported_object
(
klass
,
relation_hash
)
relation_hash
[
'source_project_id'
]
=
-
1
end
end
end
relation_hash
[
'target_project_id'
]
=
project_id
if
relation_hash
[
'target_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'
]
end
end
def
relation_class
(
relation_sym
)
def
relation_class
(
relation_sym
)
...
@@ -103,7 +78,6 @@ module Gitlab
...
@@ -103,7 +78,6 @@ module Gitlab
def
imported_object
(
klass
,
relation_hash
)
def
imported_object
(
klass
,
relation_hash
)
imported_object
=
klass
.
new
(
relation_hash
)
imported_object
=
klass
.
new
(
relation_hash
)
yield
(
imported_object
)
if
block_given?
imported_object
.
importing
=
true
if
imported_object
.
respond_to?
(
:importing
)
imported_object
.
importing
=
true
if
imported_object
.
respond_to?
(
:importing
)
imported_object
imported_object
end
end
...
...
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