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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
a7e53cd2
Commit
a7e53cd2
authored
Jan 26, 2021
by
Kassio Borges
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
BulkImports: Import Epic's labels
Import the LabelLink between the Labels and Epics.
parent
e242480c
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
140 additions
and
73 deletions
+140
-73
ee/changelogs/unreleased/kassio-bulkimports-import-epic-labels.yml
...logs/unreleased/kassio-bulkimports-import-epic-labels.yml
+5
-0
ee/lib/ee/bulk_imports/groups/graphql/get_epics_query.rb
ee/lib/ee/bulk_imports/groups/graphql/get_epics_query.rb
+5
-0
ee/lib/ee/bulk_imports/groups/loaders/epics_loader.rb
ee/lib/ee/bulk_imports/groups/loaders/epics_loader.rb
+7
-1
ee/lib/ee/bulk_imports/groups/transformers/epic_attributes_transformer.rb
...mports/groups/transformers/epic_attributes_transformer.rb
+12
-3
ee/spec/lib/ee/bulk_imports/groups/loaders/epics_loader_spec.rb
...c/lib/ee/bulk_imports/groups/loaders/epics_loader_spec.rb
+32
-18
ee/spec/lib/ee/bulk_imports/groups/pipelines/epics_pipeline_spec.rb
...b/ee/bulk_imports/groups/pipelines/epics_pipeline_spec.rb
+8
-5
ee/spec/lib/ee/bulk_imports/groups/transformers/epic_attributes_transformer_spec.rb
...s/groups/transformers/epic_attributes_transformer_spec.rb
+71
-46
No files found.
ee/changelogs/unreleased/kassio-bulkimports-import-epic-labels.yml
0 → 100644
View file @
a7e53cd2
---
title
:
"
BulkImports:
Import
Epic's
labels"
merge_request
:
52626
author
:
type
:
changed
ee/lib/ee/bulk_imports/groups/graphql/get_epics_query.rb
View file @
a7e53cd2
...
...
@@ -42,6 +42,11 @@ module EE
iid
}
}
labels {
nodes {
title
}
}
}
}
}
...
...
ee/lib/ee/bulk_imports/groups/loaders/epics_loader.rb
View file @
a7e53cd2
...
...
@@ -12,7 +12,7 @@ module EE
end
def
load
(
context
,
data
)
raise
NotAllowedError
unless
context
.
current_user
.
can?
(
:create_epic
,
context
.
group
)
raise
NotAllowedError
unless
authorized?
(
context
)
# Use `Epic` directly when creating new epics
# instead of `Epics::CreateService` since several
...
...
@@ -20,6 +20,12 @@ module EE
# group_id, parent, children need to be custom set
::
Epic
.
create!
(
data
)
end
private
def
authorized?
(
context
)
Ability
.
allowed?
(
context
.
current_user
,
:admin_epic
,
context
.
group
)
end
end
end
end
...
...
ee/lib/ee/bulk_imports/groups/transformers/epic_attributes_transformer.rb
View file @
a7e53cd2
...
...
@@ -13,12 +13,13 @@ module EE
.
then
{
|
data
|
add_author_id
(
context
,
data
)
}
.
then
{
|
data
|
add_parent
(
context
,
data
)
}
.
then
{
|
data
|
add_children
(
context
,
data
)
}
.
then
{
|
data
|
add_labels
(
context
,
data
)
}
end
private
def
add_group_id
(
context
,
data
)
data
.
merge
(
'group_id'
=>
context
.
entity
.
namespace_
id
)
data
.
merge
(
'group_id'
=>
context
.
group
.
id
)
end
def
add_author_id
(
context
,
data
)
...
...
@@ -27,7 +28,7 @@ module EE
def
add_parent
(
context
,
data
)
data
.
merge
(
'parent'
=>
context
.
entity
.
group
.
epics
.
find_by_iid
(
data
.
dig
(
'parent'
,
'iid'
))
'parent'
=>
context
.
group
.
epics
.
find_by_iid
(
data
.
dig
(
'parent'
,
'iid'
))
)
end
...
...
@@ -35,7 +36,15 @@ module EE
nodes
=
Array
.
wrap
(
data
.
dig
(
'children'
,
'nodes'
))
children_iids
=
nodes
.
filter_map
{
|
child
|
child
[
'iid'
]
}
data
.
merge
(
'children'
=>
context
.
entity
.
group
.
epics
.
where
(
iid:
children_iids
))
# rubocop: disable CodeReuse/ActiveRecord
data
.
merge
(
'children'
=>
context
.
group
.
epics
.
where
(
iid:
children_iids
))
# rubocop: disable CodeReuse/ActiveRecord
end
def
add_labels
(
context
,
data
)
data
[
'labels'
]
=
data
.
dig
(
'labels'
,
'nodes'
).
filter_map
do
|
node
|
context
.
group
.
labels
.
find_by_title
(
node
[
'title'
])
end
data
end
end
end
...
...
ee/spec/lib/ee/bulk_imports/groups/loaders/epics_loader_spec.rb
View file @
a7e53cd2
...
...
@@ -4,32 +4,46 @@ require 'spec_helper'
RSpec
.
describe
EE
::
BulkImports
::
Groups
::
Loaders
::
EpicsLoader
do
describe
'#load'
do
let
(
:user
)
{
create
(
:user
)
}
let
(
:group
)
{
create
(
:group
)
}
let
(
:bulk_import
)
{
create
(
:bulk_import
,
user:
user
)
}
let
(
:entity
)
{
create
(
:bulk_import_entity
,
bulk_import:
bulk_import
,
group:
group
)
}
let
(
:context
)
{
BulkImports
::
Pipeline
::
Context
.
new
(
entity
)
}
it
'creates the epic'
do
stub_licensed_features
(
epics:
true
)
user
=
create
(
:user
)
group
=
create
(
:group
)
group
.
add_owner
(
user
)
parent_epic
=
create
(
:epic
,
group:
group
)
child_epic
=
create
(
:epic
,
group:
group
)
label
=
create
(
:group_label
,
group:
group
)
bulk_import
=
create
(
:bulk_import
,
user:
user
)
entity
=
create
(
:bulk_import_entity
,
bulk_import:
bulk_import
,
group:
group
)
context
=
BulkImports
::
Pipeline
::
Context
.
new
(
entity
)
let
(
:data
)
do
{
'title'
=>
'epic1'
,
data
=
{
'title'
=>
'epic'
,
'state'
=>
'opened'
,
'confidential'
=>
false
,
'iid'
=>
1
,
'iid'
=>
99
,
'author_id'
=>
user
.
id
,
'group_id'
=>
group
.
id
'group_id'
=>
group
.
id
,
'parent'
=>
parent_epic
,
'children'
=>
[
child_epic
],
'labels'
=>
[
label
]
}
end
before
do
stub_licensed_features
(
epics:
true
)
group
.
add_owner
(
user
)
end
it
'creates the epic'
do
expect
{
subject
.
load
(
context
,
data
)
}.
to
change
(
::
Epic
,
:count
).
by
(
1
)
expect
(
group
.
epics
.
count
).
to
eq
(
1
)
epic
=
group
.
epics
.
last
expect
(
epic
.
group
).
to
eq
(
group
)
expect
(
epic
.
author
).
to
eq
(
user
)
expect
(
epic
.
title
).
to
eq
(
'epic'
)
expect
(
epic
.
state
).
to
eq
(
'opened'
)
expect
(
epic
.
confidential
).
to
eq
(
false
)
expect
(
epic
.
iid
).
to
eq
(
99
)
expect
(
epic
.
parent
).
to
eq
(
parent_epic
)
expect
(
epic
.
children
).
to
contain_exactly
(
child_epic
)
expect
(
epic
.
labels
).
to
contain_exactly
(
label
)
end
end
end
ee/spec/lib/ee/bulk_imports/groups/pipelines/epics_pipeline_spec.rb
View file @
a7e53cd2
...
...
@@ -3,18 +3,18 @@
require
'spec_helper'
RSpec
.
describe
EE
::
BulkImports
::
Groups
::
Pipelines
::
EpicsPipeline
do
let
(
:cursor
)
{
'cursor'
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:group
)
{
create
(
:group
)
}
let
(
:cursor
)
{
'cursor'
}
let
(
:bulk_import
)
{
create
(
:bulk_import
,
user:
user
)
}
let
(
:entity
)
do
create
(
:bulk_import_entity
,
group:
group
,
bulk_import:
bulk_import
,
source_full_path:
'source/full/path'
,
destination_name:
'My Destination Group'
,
destination_namespace:
group
.
full_path
,
group:
group
,
bulk_import:
bulk_import
destination_namespace:
group
.
full_path
)
end
...
...
@@ -104,7 +104,10 @@ RSpec.describe EE::BulkImports::Groups::Pipelines::EpicsPipeline do
{
'title'
=>
'epic1'
,
'state'
=>
'closed'
,
'confidential'
=>
true
'confidential'
=>
true
,
'labels'
=>
{
'nodes'
=>
[]
}
}
]
...
...
ee/spec/lib/ee/bulk_imports/groups/transformers/epic_attributes_transformer_spec.rb
View file @
a7e53cd2
...
...
@@ -3,69 +3,94 @@
require
'spec_helper'
RSpec
.
describe
EE
::
BulkImports
::
Groups
::
Transformers
::
EpicAttributesTransformer
do
describe
'#transform'
do
let
(
:user
)
{
create
(
:user
)
}
let
(
:group
)
{
create
(
:group
,
name:
'My Source Group'
)
}
let
(
:entity
)
do
instance_double
(
BulkImports
::
Entity
,
group:
group
,
namespace_id:
group
.
id
)
end
let
(
:user
)
{
create
(
:user
)
}
let
(
:group
)
{
create
(
:group
)
}
let
(
:bulk_import
)
{
create
(
:bulk_import
,
user:
user
)
}
let
(
:entity
)
{
create
(
:bulk_import_entity
,
bulk_import:
bulk_import
,
group:
group
)
}
let
(
:context
)
{
::
BulkImports
::
Pipeline
::
Context
.
new
(
entity
)
}
let
(
:context
)
do
instance_double
(
BulkImports
::
Pipeline
::
Context
,
current_user:
user
,
entity:
entity
)
end
describe
'#transform'
do
it
'transforms the epic attributes'
do
transformed
=
subject
.
transform
(
context
,
epic_data
)
let
(
:data
)
do
{
'iid'
=>
'7'
,
'title'
=>
'Epic Title'
,
'description'
=>
'Epic Description'
,
expect
(
transformed
).
to
eq
({
'title'
=>
'title'
,
'description'
=>
'description'
,
'state'
=>
'opened'
,
'parent'
=>
{
'iid'
=>
parent_iid
},
'children'
=>
{
'nodes'
=>
[
{
'iid'
=>
child_iid
}
]
}
}
'create_at'
=>
'2021-01-27T03:42:30Z'
,
'closed_at'
=>
nil
,
'start_date'
=>
nil
,
'start_date_fixed'
=>
nil
,
'start_date_is_fixed'
=>
false
,
'due_date_fixed'
=>
nil
,
'due_date_is_fixed'
=>
false
,
'relative_position'
=>
1073716855
,
'confidential'
=>
false
,
'group_id'
=>
group
.
id
,
'author_id'
=>
user
.
id
,
'parent'
=>
nil
,
'children'
=>
[],
'labels'
=>
[]
})
end
context
'when parent and child iids are nil'
do
let
(
:parent_iid
)
{
nil
}
let
(
:child_iid
)
{
nil
}
context
'labels'
do
it
'maps the existing labels'
do
label
=
create
(
:group_label
,
group:
group
)
data
=
epic_data
(
labels_titles:
[
label
.
title
,
'NON EXISTING TITLE'
])
it
'sets group_id, author_id from context'
do
transformed_data
=
subject
.
transform
(
context
,
data
)
expect
(
transformed_data
[
'group_id'
]).
to
eq
(
group
.
id
)
expect
(
transformed_data
[
'author_id'
]).
to
eq
(
user
.
id
)
expect
(
transformed_data
[
'parent'
]).
to
be_nil
expect
(
transformed_data
[
'labels'
].
to_a
).
to
contain_exactly
(
label
)
end
end
context
'
when parent and child iids are present
'
do
let
(
:parent
)
{
create
(
:epic
,
group:
group
)
}
let
(
:child
)
{
create
(
:epic
,
group:
group
)
}
let
(
:parent_iid
)
{
parent
.
iid
}
let
(
:child_iid
)
{
child
.
iid
}
context
'
parent and children epics
'
do
it
'sets parent and child epics when they exist'
do
parent
=
create
(
:epic
,
group:
group
)
child
=
create
(
:epic
,
group:
group
)
data
=
epic_data
(
parent_iid:
parent
.
iid
,
children_iids:
[
child
.
iid
])
it
'sets parent and child epics'
do
transformed_data
=
subject
.
transform
(
context
,
data
)
expect
(
transformed_data
[
'parent'
]).
to
eq
(
parent
)
expect
(
transformed_data
[
'children'
]).
to
contain_exactly
(
child
)
end
it
'removes the parent and children id when they dont exist'
do
data
=
epic_data
(
parent_iid:
9998
,
children_iids:
[
9999
])
transformed_data
=
subject
.
transform
(
context
,
data
)
expect
(
transformed_data
[
'parent'
]).
to
be_nil
expect
(
transformed_data
[
'children'
]).
to
be_empty
end
end
def
epic_data
(
parent_iid:
nil
,
children_iids:
[],
labels_titles:
[])
{
'title'
=>
'title'
,
'description'
=>
'description'
,
'state'
=>
'opened'
,
'create_at'
=>
'2021-01-27T03:42:30Z'
,
'closed_at'
=>
nil
,
'start_date'
=>
nil
,
'start_date_fixed'
=>
nil
,
'start_date_is_fixed'
=>
false
,
'due_date_fixed'
=>
nil
,
'due_date_is_fixed'
=>
false
,
'relative_position'
=>
1073716855
,
'confidential'
=>
false
,
'parent'
=>
{
'iid'
=>
parent_iid
},
'children'
=>
{
'nodes'
=>
children_iids
.
map
{
|
iid
|
{
'iid'
=>
iid
}
}
},
'labels'
=>
{
'nodes'
=>
labels_titles
.
map
{
|
title
|
{
'title'
=>
title
}
}
}
}
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