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
Boxiang Sun
gitlab-ce
Commits
a8d9dbc1
Commit
a8d9dbc1
authored
Oct 05, 2017
by
micael.bergeron
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix the project import when an issue has a group milestone
parent
09a733ba
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
101 additions
and
81 deletions
+101
-81
lib/gitlab/import_export/relation_factory.rb
lib/gitlab/import_export/relation_factory.rb
+9
-2
spec/lib/gitlab/import_export/project.light.json
spec/lib/gitlab/import_export/project.light.json
+7
-32
spec/lib/gitlab/import_export/project_tree_restorer_spec.rb
spec/lib/gitlab/import_export/project_tree_restorer_spec.rb
+85
-47
No files found.
lib/gitlab/import_export/relation_factory.rb
View file @
a8d9dbc1
...
@@ -35,7 +35,7 @@ module Gitlab
...
@@ -35,7 +35,7 @@ module Gitlab
def
initialize
(
relation_sym
:,
relation_hash
:,
members_mapper
:,
user
:,
project
:)
def
initialize
(
relation_sym
:,
relation_hash
:,
members_mapper
:,
user
:,
project
:)
@relation_name
=
OVERRIDES
[
relation_sym
]
||
relation_sym
@relation_name
=
OVERRIDES
[
relation_sym
]
||
relation_sym
@relation_hash
=
relation_hash
.
except
(
'noteable_id'
)
.
merge
(
'project_id'
=>
project
.
id
)
@relation_hash
=
relation_hash
.
except
(
'noteable_id'
)
@members_mapper
=
members_mapper
@members_mapper
=
members_mapper
@user
=
user
@user
=
user
@project
=
project
@project
=
project
...
@@ -248,7 +248,14 @@ module Gitlab
...
@@ -248,7 +248,14 @@ module Gitlab
end
end
def
find_or_create_object!
def
find_or_create_object!
finder_attributes
=
@relation_name
==
:group_label
?
%w[title group_id]
:
%w[title project_id]
# TODO: Trying to find how I can correctly use the correct id depending on the object's type
finder_attributes
=
if
@relation_type
==
:group_label
%w[title group_id]
elsif
parsed_relation_hash
[
'project_id'
]
%w[title project_id]
else
%w[title group_id]
end
finder_hash
=
parsed_relation_hash
.
slice
(
*
finder_attributes
)
finder_hash
=
parsed_relation_hash
.
slice
(
*
finder_attributes
)
if
label?
if
label?
...
...
spec/lib/gitlab/import_export/project.light.json
View file @
a8d9dbc1
...
@@ -5,9 +5,9 @@
...
@@ -5,9 +5,9 @@
"milestones"
:
[
"milestones"
:
[
{
{
"id"
:
1
,
"id"
:
1
,
"title"
:
"
tes
t milestone"
,
"title"
:
"
Projec
t milestone"
,
"project_id"
:
8
,
"project_id"
:
8
,
"description"
:
"
test
milestone"
,
"description"
:
"
Project-level
milestone"
,
"due_date"
:
null
,
"due_date"
:
null
,
"created_at"
:
"2016-06-14T15:02:04.415Z"
,
"created_at"
:
"2016-06-14T15:02:04.415Z"
,
"updated_at"
:
"2016-06-14T15:02:04.415Z"
,
"updated_at"
:
"2016-06-14T15:02:04.415Z"
,
...
@@ -65,9 +65,9 @@
...
@@ -65,9 +65,9 @@
"group_milestone_id"
:
null
,
"group_milestone_id"
:
null
,
"milestone"
:
{
"milestone"
:
{
"id"
:
1
,
"id"
:
1
,
"title"
:
"
tes
t milestone"
,
"title"
:
"
Projec
t milestone"
,
"project_id"
:
8
,
"project_id"
:
8
,
"description"
:
"
test
milestone"
,
"description"
:
"
Project-level
milestone"
,
"due_date"
:
null
,
"due_date"
:
null
,
"created_at"
:
"2016-06-14T15:02:04.415Z"
,
"created_at"
:
"2016-06-14T15:02:04.415Z"
,
"updated_at"
:
"2016-06-14T15:02:04.415Z"
,
"updated_at"
:
"2016-06-14T15:02:04.415Z"
,
...
@@ -76,27 +76,6 @@
...
@@ -76,27 +76,6 @@
"group_id"
:
null
"group_id"
:
null
},
},
"label_links"
:
[
"label_links"
:
[
{
"id"
:
11
,
"label_id"
:
6
,
"target_id"
:
1
,
"target_type"
:
"Issue"
,
"created_at"
:
"2017-08-15T18:37:40.795Z"
,
"updated_at"
:
"2017-08-15T18:37:40.795Z"
,
"label"
:
{
"id"
:
6
,
"title"
:
"group label"
,
"color"
:
"#A8D695"
,
"project_id"
:
null
,
"created_at"
:
"2017-08-15T18:37:19.698Z"
,
"updated_at"
:
"2017-08-15T18:37:19.698Z"
,
"template"
:
false
,
"description"
:
""
,
"group_id"
:
5
,
"type"
:
"GroupLabel"
,
"priorities"
:
[]
}
},
{
{
"id"
:
11
,
"id"
:
11
,
"label_id"
:
2
,
"label_id"
:
2
,
...
@@ -113,7 +92,7 @@
...
@@ -113,7 +92,7 @@
"updated_at"
:
"2017-08-15T18:37:19.698Z"
,
"updated_at"
:
"2017-08-15T18:37:19.698Z"
,
"template"
:
false
,
"template"
:
false
,
"description"
:
""
,
"description"
:
""
,
"group_id"
:
5
,
"group_id"
:
null
,
"type"
:
"ProjectLabel"
,
"type"
:
"ProjectLabel"
,
"priorities"
:
[]
"priorities"
:
[]
}
}
...
@@ -121,10 +100,6 @@
...
@@ -121,10 +100,6 @@
]
]
}
}
],
],
"snippets"
:
[
"snippets"
:
[],
"hooks"
:
[]
],
"hooks"
:
[
]
}
}
spec/lib/gitlab/import_export/project_tree_restorer_spec.rb
View file @
a8d9dbc1
...
@@ -182,6 +182,53 @@ describe Gitlab::ImportExport::ProjectTreeRestorer do
...
@@ -182,6 +182,53 @@ describe Gitlab::ImportExport::ProjectTreeRestorer do
end
end
end
end
shared_examples
'restores project successfully'
do
it
'correctly restores project'
do
expect
(
shared
.
errors
).
to
be_empty
expect
(
restored_project_json
).
to
be_truthy
end
end
shared_examples
'restores project correctly'
do
|**
results
|
it
'has labels'
do
expect
(
project
.
labels
.
size
).
to
eq
(
results
.
fetch
(
:labels
,
0
))
end
it
'has label priorities'
do
expect
(
project
.
labels
.
first
.
priorities
).
not_to
be_empty
end
it
'has milestones'
do
expect
(
project
.
milestones
.
size
).
to
eq
(
results
.
fetch
(
:milestones
,
0
))
end
it
'has issues'
do
expect
(
project
.
issues
.
size
).
to
eq
(
results
.
fetch
(
:issues
,
0
))
end
it
'has issue with group label and project label'
do
labels
=
project
.
issues
.
first
.
labels
expect
(
labels
.
where
(
type:
"ProjectLabel"
).
count
).
to
eq
(
results
.
fetch
(
:first_issue_labels
,
0
))
end
end
shared_examples
'restores group correctly'
do
|**
results
|
it
'has group label'
do
expect
(
project
.
group
.
labels
.
size
).
to
eq
(
results
.
fetch
(
:labels
,
0
))
end
it
'has group milestone'
do
expect
(
project
.
group
.
milestones
.
size
).
to
eq
(
results
.
fetch
(
:milestones
,
0
))
end
it
'has issue with group label'
do
labels
=
project
.
issues
.
first
.
labels
expect
(
labels
.
where
(
type:
"GroupLabel"
).
count
).
to
eq
(
results
.
fetch
(
:first_issue_labels
,
0
))
end
end
context
'Light JSON'
do
context
'Light JSON'
do
let
(
:user
)
{
create
(
:user
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:shared
)
{
Gitlab
::
ImportExport
::
Shared
.
new
(
relative_path:
""
,
project_path:
'path'
)
}
let
(
:shared
)
{
Gitlab
::
ImportExport
::
Shared
.
new
(
relative_path:
""
,
project_path:
'path'
)
}
...
@@ -190,33 +237,45 @@ describe Gitlab::ImportExport::ProjectTreeRestorer do
...
@@ -190,33 +237,45 @@ describe Gitlab::ImportExport::ProjectTreeRestorer do
let
(
:restored_project_json
)
{
project_tree_restorer
.
restore
}
let
(
:restored_project_json
)
{
project_tree_restorer
.
restore
}
before
do
before
do
project_tree_restorer
.
instance_variable_set
(
:@path
,
"spec/lib/gitlab/import_export/project.light.json"
)
allow
(
shared
).
to
receive
(
:export_path
).
and_return
(
'spec/lib/gitlab/import_export/'
)
allow
(
shared
).
to
receive
(
:export_path
).
and_return
(
'spec/lib/gitlab/import_export/'
)
end
end
context
'project.json file access check'
do
context
'with a simple project'
do
it
'does not read a symlink'
do
before
do
Dir
.
mktmpdir
do
|
tmpdir
|
project_tree_restorer
.
instance_variable_set
(
:@path
,
"spec/lib/gitlab/import_export/project.light.json"
)
setup_symlink
(
tmpdir
,
'project.json'
)
allow
(
shared
).
to
receive
(
:export_path
).
and_call_original
restored_project_json
end
it_behaves_like
'restores project correctly'
,
issues:
1
,
labels:
1
,
milestones:
1
,
first_issue_labels:
1
restored_project_json
context
'project.json file access check'
do
it
'does not read a symlink'
do
Dir
.
mktmpdir
do
|
tmpdir
|
setup_symlink
(
tmpdir
,
'project.json'
)
allow
(
shared
).
to
receive
(
:export_path
).
and_call_original
expect
(
shared
.
errors
).
to
be_empty
restored_project_json
expect
(
shared
.
errors
).
to
be_empty
end
end
end
end
end
end
context
'when there is an existing build with build token'
do
context
'when there is an existing build with build token'
do
it
'restores project json correctly'
do
before
do
create
(
:ci_build
,
token:
'abcd'
)
create
(
:ci_build
,
token:
'abcd'
)
end
expect
(
restored_project_json
).
to
be_truthy
it_behaves_like
'restores project successfully'
end
end
end
end
context
'with group'
do
context
'with
a project that has a
group'
do
let!
(
:project
)
do
let!
(
:project
)
do
create
(
:project
,
create
(
:project
,
:builds_disabled
,
:builds_disabled
,
...
@@ -227,43 +286,22 @@ describe Gitlab::ImportExport::ProjectTreeRestorer do
...
@@ -227,43 +286,22 @@ describe Gitlab::ImportExport::ProjectTreeRestorer do
end
end
before
do
before
do
project_tree_restorer
.
instance_variable_set
(
:@path
,
"spec/lib/gitlab/import_export/project.
light
.json"
)
project_tree_restorer
.
instance_variable_set
(
:@path
,
"spec/lib/gitlab/import_export/project.
group
.json"
)
restored_project_json
restored_project_json
end
end
it
'correctly restores project'
do
it_behaves_like
'restores project successfully'
expect
(
shared
.
errors
).
to
be_empty
it_behaves_like
'restores project correctly'
,
expect
(
restored_project_json
).
to
be_truthy
issues:
2
,
end
labels:
1
,
milestones:
1
,
first_issue_labels:
1
it
'has labels'
do
it_behaves_like
'restores group correctly'
,
expect
(
project
.
labels
.
count
).
to
eq
(
2
)
labels:
1
,
end
milestones:
1
,
first_issue_labels:
1
it
'creates group label'
do
expect
(
project
.
group
.
labels
.
count
).
to
eq
(
1
)
end
it
'has label priorities'
do
expect
(
project
.
labels
.
first
.
priorities
).
not_to
be_empty
end
it
'has milestones'
do
expect
(
project
.
milestones
.
count
).
to
eq
(
1
)
end
it
'has issue'
do
expect
(
project
.
issues
.
count
).
to
eq
(
1
)
expect
(
project
.
issues
.
first
.
labels
.
count
).
to
eq
(
2
)
end
it
'has issue with group label and project label'
do
labels
=
project
.
issues
.
first
.
labels
expect
(
labels
.
where
(
type:
"GroupLabel"
).
count
).
to
eq
(
1
)
expect
(
labels
.
where
(
type:
"ProjectLabel"
).
count
).
to
eq
(
1
)
end
end
end
end
end
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