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
Show 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
def
initialize
(
relation_sym
:,
relation_hash
:,
members_mapper
:,
user
:,
project
:)
@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
@user
=
user
@project
=
project
...
...
@@ -248,7 +248,14 @@ module Gitlab
end
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
)
if
label?
...
...
spec/lib/gitlab/import_export/project.light.json
View file @
a8d9dbc1
...
...
@@ -5,9 +5,9 @@
"milestones"
:
[
{
"id"
:
1
,
"title"
:
"
tes
t milestone"
,
"title"
:
"
Projec
t milestone"
,
"project_id"
:
8
,
"description"
:
"
test
milestone"
,
"description"
:
"
Project-level
milestone"
,
"due_date"
:
null
,
"created_at"
:
"2016-06-14T15:02:04.415Z"
,
"updated_at"
:
"2016-06-14T15:02:04.415Z"
,
...
...
@@ -65,9 +65,9 @@
"group_milestone_id"
:
null
,
"milestone"
:
{
"id"
:
1
,
"title"
:
"
tes
t milestone"
,
"title"
:
"
Projec
t milestone"
,
"project_id"
:
8
,
"description"
:
"
test
milestone"
,
"description"
:
"
Project-level
milestone"
,
"due_date"
:
null
,
"created_at"
:
"2016-06-14T15:02:04.415Z"
,
"updated_at"
:
"2016-06-14T15:02:04.415Z"
,
...
...
@@ -76,27 +76,6 @@
"group_id"
:
null
},
"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
,
"label_id"
:
2
,
...
...
@@ -113,7 +92,7 @@
"updated_at"
:
"2017-08-15T18:37:19.698Z"
,
"template"
:
false
,
"description"
:
""
,
"group_id"
:
5
,
"group_id"
:
null
,
"type"
:
"ProjectLabel"
,
"priorities"
:
[]
}
...
...
@@ -121,10 +100,6 @@
]
}
],
"snippets"
:
[
],
"hooks"
:
[
]
"snippets"
:
[],
"hooks"
:
[]
}
spec/lib/gitlab/import_export/project_tree_restorer_spec.rb
View file @
a8d9dbc1
...
...
@@ -182,6 +182,53 @@ describe Gitlab::ImportExport::ProjectTreeRestorer do
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
let
(
:user
)
{
create
(
:user
)
}
let
(
:shared
)
{
Gitlab
::
ImportExport
::
Shared
.
new
(
relative_path:
""
,
project_path:
'path'
)
}
...
...
@@ -189,12 +236,23 @@ describe Gitlab::ImportExport::ProjectTreeRestorer do
let
(
:project_tree_restorer
)
{
described_class
.
new
(
user:
user
,
shared:
shared
,
project:
project
)
}
let
(
:restored_project_json
)
{
project_tree_restorer
.
restore
}
before
do
allow
(
shared
).
to
receive
(
:export_path
).
and_return
(
'spec/lib/gitlab/import_export/'
)
end
context
'with a simple project'
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/'
)
restored_project_json
end
it_behaves_like
'restores project correctly'
,
issues:
1
,
labels:
1
,
milestones:
1
,
first_issue_labels:
1
context
'project.json file access check'
do
it
'does not read a symlink'
do
Dir
.
mktmpdir
do
|
tmpdir
|
...
...
@@ -209,14 +267,15 @@ describe Gitlab::ImportExport::ProjectTreeRestorer do
end
context
'when there is an existing build with build token'
do
it
'restores project json correctly'
do
before
do
create
(
:ci_build
,
token:
'abcd'
)
end
expect
(
restored_project_json
).
to
be_truthy
it_behaves_like
'restores project successfully'
end
end
context
'with group'
do
context
'with
a project that has a
group'
do
let!
(
:project
)
do
create
(
:project
,
:builds_disabled
,
...
...
@@ -227,43 +286,22 @@ describe Gitlab::ImportExport::ProjectTreeRestorer do
end
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
end
it
'correctly restores project'
do
expect
(
shared
.
errors
).
to
be_empty
expect
(
restored_project_json
).
to
be_truthy
end
it_behaves_like
'restores project successfully'
it_behaves_like
'restores project correctly'
,
issues:
2
,
labels:
1
,
milestones:
1
,
first_issue_labels:
1
it
'has labels'
do
expect
(
project
.
labels
.
count
).
to
eq
(
2
)
end
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
it_behaves_like
'restores group correctly'
,
labels:
1
,
milestones:
1
,
first_issue_labels:
1
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