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
77b7bfd4
Commit
77b7bfd4
authored
Sep 29, 2016
by
James Lopez
Committed by
Douglas Barbosa Alexandre
Oct 19, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix import/export labels to cope with project and group labels. Added relevant specs.
parent
848a146f
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
94 additions
and
12 deletions
+94
-12
doc/user/project/settings/import_export.md
doc/user/project/settings/import_export.md
+2
-1
lib/gitlab/import_export.rb
lib/gitlab/import_export.rb
+1
-1
lib/gitlab/import_export/import_export.yml
lib/gitlab/import_export/import_export.yml
+1
-1
lib/gitlab/import_export/project_tree_restorer.rb
lib/gitlab/import_export/project_tree_restorer.rb
+6
-1
lib/gitlab/import_export/relation_factory.rb
lib/gitlab/import_export/relation_factory.rb
+18
-2
spec/lib/gitlab/import_export/project.json
spec/lib/gitlab/import_export/project.json
+25
-2
spec/lib/gitlab/import_export/project_tree_restorer_spec.rb
spec/lib/gitlab/import_export/project_tree_restorer_spec.rb
+28
-1
spec/lib/gitlab/import_export/project_tree_saver_spec.rb
spec/lib/gitlab/import_export/project_tree_saver_spec.rb
+13
-3
No files found.
doc/user/project/settings/import_export.md
View file @
77b7bfd4
...
@@ -22,7 +22,8 @@ with all their related data and be moved into a new GitLab instance.
...
@@ -22,7 +22,8 @@ with all their related data and be moved into a new GitLab instance.
| GitLab version | Import/Export version |
| GitLab version | Import/Export version |
| -------- | -------- |
| -------- | -------- |
| 8.12.0 to current | 0.1.4 |
| 8.13.0 to current | 0.1.5 |
| 8.12.0 | 0.1.4 |
| 8.10.3 | 0.1.3 |
| 8.10.3 | 0.1.3 |
| 8.10.0 | 0.1.2 |
| 8.10.0 | 0.1.2 |
| 8.9.5 | 0.1.1 |
| 8.9.5 | 0.1.1 |
...
...
lib/gitlab/import_export.rb
View file @
77b7bfd4
...
@@ -3,7 +3,7 @@ module Gitlab
...
@@ -3,7 +3,7 @@ module Gitlab
extend
self
extend
self
# For every version update, the version history in import_export.md has to be kept up to date.
# For every version update, the version history in import_export.md has to be kept up to date.
VERSION
=
'0.1.
4
'
VERSION
=
'0.1.
5
'
FILENAME_LIMIT
=
50
FILENAME_LIMIT
=
50
def
export_path
(
relative_path
:)
def
export_path
(
relative_path
:)
...
...
lib/gitlab/import_export/import_export.yml
View file @
77b7bfd4
...
@@ -71,7 +71,7 @@ excluded_attributes:
...
@@ -71,7 +71,7 @@ excluded_attributes:
-
:awardable_id
-
:awardable_id
methods
:
methods
:
project_
labels
:
labels
:
-
:type
-
:type
label
:
label
:
-
:type
-
:type
...
...
lib/gitlab/import_export/project_tree_restorer.rb
View file @
77b7bfd4
...
@@ -110,7 +110,7 @@ module Gitlab
...
@@ -110,7 +110,7 @@ module Gitlab
def
create_relation
(
relation
,
relation_hash_list
)
def
create_relation
(
relation
,
relation_hash_list
)
relation_array
=
[
relation_hash_list
].
flatten
.
map
do
|
relation_hash
|
relation_array
=
[
relation_hash_list
].
flatten
.
map
do
|
relation_hash
|
Gitlab
::
ImportExport
::
RelationFactory
.
create
(
relation_sym:
relation
.
to_sym
,
Gitlab
::
ImportExport
::
RelationFactory
.
create
(
relation_sym:
relation
.
to_sym
,
relation_hash:
relation_hash
,
relation_hash:
parsed_relation_hash
(
relation_hash
)
,
members_mapper:
members_mapper
,
members_mapper:
members_mapper
,
user:
@user
,
user:
@user
,
project_id:
restored_project
.
id
)
project_id:
restored_project
.
id
)
...
@@ -118,6 +118,11 @@ module Gitlab
...
@@ -118,6 +118,11 @@ module Gitlab
relation_hash_list
.
is_a?
(
Array
)
?
relation_array
:
relation_array
.
first
relation_hash_list
.
is_a?
(
Array
)
?
relation_array
:
relation_array
.
first
end
end
def
parsed_relation_hash
(
relation_hash
)
group_id
=
restored_project
.
group
?
restored_project
.
group
.
id
:
nil
relation_hash
.
merge!
(
'group_id'
=>
group_id
,
'project_id'
=>
restored_project
.
id
)
end
end
end
end
end
end
end
lib/gitlab/import_export/relation_factory.rb
View file @
77b7bfd4
...
@@ -10,7 +10,8 @@ module Gitlab
...
@@ -10,7 +10,8 @@ module Gitlab
hooks:
'ProjectHook'
,
hooks:
'ProjectHook'
,
merge_access_levels:
'ProtectedBranch::MergeAccessLevel'
,
merge_access_levels:
'ProtectedBranch::MergeAccessLevel'
,
push_access_levels:
'ProtectedBranch::PushAccessLevel'
,
push_access_levels:
'ProtectedBranch::PushAccessLevel'
,
labels: :project_labels
}.
freeze
labels: :project_labels
,
label: :project_label
}.
freeze
USER_REFERENCES
=
%w[author_id assignee_id updated_by_id user_id]
.
freeze
USER_REFERENCES
=
%w[author_id assignee_id updated_by_id user_id]
.
freeze
...
@@ -20,7 +21,7 @@ module Gitlab
...
@@ -20,7 +21,7 @@ module Gitlab
IMPORTED_OBJECT_MAX_RETRIES
=
5
.
freeze
IMPORTED_OBJECT_MAX_RETRIES
=
5
.
freeze
EXISTING_OBJECT_CHECK
=
%i[milestone milestones label labels project_label project_labels]
.
freeze
EXISTING_OBJECT_CHECK
=
%i[milestone milestones label labels project_label project_labels
project_label group_label
]
.
freeze
FINDER_ATTRIBUTES
=
%w[title project_id]
.
freeze
FINDER_ATTRIBUTES
=
%w[title project_id]
.
freeze
...
@@ -57,6 +58,8 @@ module Gitlab
...
@@ -57,6 +58,8 @@ module Gitlab
update_user_references
update_user_references
update_project_references
update_project_references
handle_group_label
if
group_label?
reset_ci_tokens
if
@relation_name
==
'Ci::Trigger'
reset_ci_tokens
if
@relation_name
==
'Ci::Trigger'
@relation_hash
[
'data'
].
deep_symbolize_keys!
if
@relation_name
==
:events
&&
@relation_hash
[
'data'
]
@relation_hash
[
'data'
].
deep_symbolize_keys!
if
@relation_name
==
:events
&&
@relation_hash
[
'data'
]
set_st_diffs
if
@relation_name
==
:merge_request_diff
set_st_diffs
if
@relation_name
==
:merge_request_diff
...
@@ -124,6 +127,19 @@ module Gitlab
...
@@ -124,6 +127,19 @@ module Gitlab
@relation_hash
[
'target_project_id'
]
&&
@relation_hash
[
'target_project_id'
]
==
@relation_hash
[
'source_project_id'
]
@relation_hash
[
'target_project_id'
]
&&
@relation_hash
[
'target_project_id'
]
==
@relation_hash
[
'source_project_id'
]
end
end
def
group_label?
@relation_hash
[
'type'
]
==
'GroupLabel'
end
def
handle_group_label
# If there's no group, move the label to a project label
if
@relation_hash
[
'group_id'
]
@relation_name
=
:group_label
else
@relation_hash
[
'type'
]
=
'ProjectLabel'
end
end
def
reset_ci_tokens
def
reset_ci_tokens
return
unless
Gitlab
::
ImportExport
.
reset_tokens?
return
unless
Gitlab
::
ImportExport
.
reset_tokens?
...
...
spec/lib/gitlab/import_export/project.json
View file @
77b7bfd4
...
@@ -64,7 +64,29 @@
...
@@ -64,7 +64,29 @@
"updated_at"
:
"2016-07-22T08:55:44.161Z"
,
"updated_at"
:
"2016-07-22T08:55:44.161Z"
,
"template"
:
false
,
"template"
:
false
,
"description"
:
""
,
"description"
:
""
,
"priority"
:
null
"priority"
:
null
,
"type"
:
"ProjectLabel"
}
},
{
"id"
:
3
,
"label_id"
:
3
,
"target_id"
:
40
,
"target_type"
:
"Issue"
,
"created_at"
:
"2016-07-22T08:57:02.841Z"
,
"updated_at"
:
"2016-07-22T08:57:02.841Z"
,
"label"
:
{
"id"
:
3
,
"title"
:
"test3"
,
"color"
:
"#428bca"
,
"group_id"
:
8
,
"created_at"
:
"2016-07-22T08:55:44.161Z"
,
"updated_at"
:
"2016-07-22T08:55:44.161Z"
,
"template"
:
false
,
"description"
:
""
,
"priority"
:
null
,
"project_id"
:
null
,
"type"
:
"GroupLabel"
}
}
}
}
],
],
...
@@ -536,7 +558,8 @@
...
@@ -536,7 +558,8 @@
"updated_at"
:
"2016-07-22T08:55:44.161Z"
,
"updated_at"
:
"2016-07-22T08:55:44.161Z"
,
"template"
:
false
,
"template"
:
false
,
"description"
:
""
,
"description"
:
""
,
"priority"
:
null
"priority"
:
null
,
"type"
:
"ProjectLabel"
}
}
}
}
],
],
...
...
spec/lib/gitlab/import_export/project_tree_restorer_spec.rb
View file @
77b7bfd4
...
@@ -32,7 +32,7 @@ describe Gitlab::ImportExport::ProjectTreeRestorer, services: true do
...
@@ -32,7 +32,7 @@ describe Gitlab::ImportExport::ProjectTreeRestorer, services: true do
it
'has the same label associated to two issues'
do
it
'has the same label associated to two issues'
do
restored_project_json
restored_project_json
expect
(
Label
.
first
.
issues
.
count
).
to
eq
(
2
)
expect
(
ProjectLabel
.
find_by_title
(
'test2'
)
.
issues
.
count
).
to
eq
(
2
)
end
end
it
'has milestones associated to two separate issues'
do
it
'has milestones associated to two separate issues'
do
...
@@ -107,6 +107,33 @@ describe Gitlab::ImportExport::ProjectTreeRestorer, services: true do
...
@@ -107,6 +107,33 @@ describe Gitlab::ImportExport::ProjectTreeRestorer, services: true do
expect
(
Label
.
first
.
label_links
.
first
.
target
).
not_to
be_nil
expect
(
Label
.
first
.
label_links
.
first
.
target
).
not_to
be_nil
end
end
it
'has project labels'
do
restored_project_json
expect
(
ProjectLabel
.
count
).
to
eq
(
2
)
end
it
'has no group labels'
do
restored_project_json
expect
(
GroupLabel
.
count
).
to
eq
(
0
)
end
context
'with group'
do
let!
(
:project
)
{
create
(
:empty_project
,
name:
'project'
,
path:
'project'
,
builds_access_level:
ProjectFeature
::
DISABLED
,
issues_access_level:
ProjectFeature
::
DISABLED
,
group:
create
(
:group
))
}
it
'has group labels'
do
restored_project_json
expect
(
GroupLabel
.
count
).
to
eq
(
1
)
end
end
it
'has a project feature'
do
it
'has a project feature'
do
restored_project_json
restored_project_json
...
...
spec/lib/gitlab/import_export/project_tree_saver_spec.rb
View file @
77b7bfd4
...
@@ -111,6 +111,12 @@ describe Gitlab::ImportExport::ProjectTreeSaver, services: true do
...
@@ -111,6 +111,12 @@ describe Gitlab::ImportExport::ProjectTreeSaver, services: true do
expect
(
saved_project_json
[
'issues'
].
first
[
'label_links'
].
first
[
'label'
]).
not_to
be_empty
expect
(
saved_project_json
[
'issues'
].
first
[
'label_links'
].
first
[
'label'
]).
not_to
be_empty
end
end
it
'has project and group labels'
do
label_types
=
saved_project_json
[
'issues'
].
first
[
'label_links'
].
map
{
|
link
|
link
[
'label'
][
'type'
]}
expect
(
label_types
).
to
match
([
'ProjectLabel'
,
'GroupLabel'
])
end
it
'saves the correct service type'
do
it
'saves the correct service type'
do
expect
(
saved_project_json
[
'services'
].
first
[
'type'
]).
to
eq
(
'CustomIssueTrackerService'
)
expect
(
saved_project_json
[
'services'
].
first
[
'type'
]).
to
eq
(
'CustomIssueTrackerService'
)
end
end
...
@@ -135,15 +141,19 @@ describe Gitlab::ImportExport::ProjectTreeSaver, services: true do
...
@@ -135,15 +141,19 @@ describe Gitlab::ImportExport::ProjectTreeSaver, services: true do
issue
=
create
(
:issue
,
assignee:
user
)
issue
=
create
(
:issue
,
assignee:
user
)
snippet
=
create
(
:project_snippet
)
snippet
=
create
(
:project_snippet
)
release
=
create
(
:release
)
release
=
create
(
:release
)
group
=
create
(
:group
)
project
=
create
(
:project
,
project
=
create
(
:project
,
:public
,
:public
,
issues:
[
issue
],
issues:
[
issue
],
snippets:
[
snippet
],
snippets:
[
snippet
],
releases:
[
release
]
releases:
[
release
],
group:
group
)
)
label
=
create
(
:label
,
project:
project
)
project_label
=
create
(
:label
,
project:
project
)
create
(
:label_link
,
label:
label
,
target:
issue
)
group_label
=
create
(
:group_label
,
group:
group
)
create
(
:label_link
,
label:
project_label
,
target:
issue
)
create
(
:label_link
,
label:
group_label
,
target:
issue
)
milestone
=
create
(
:milestone
,
project:
project
)
milestone
=
create
(
:milestone
,
project:
project
)
merge_request
=
create
(
:merge_request
,
source_project:
project
,
milestone:
milestone
)
merge_request
=
create
(
:merge_request
,
source_project:
project
,
milestone:
milestone
)
commit_status
=
create
(
:commit_status
,
project:
project
)
commit_status
=
create
(
:commit_status
,
project:
project
)
...
...
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