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
6c44e1ac
Commit
6c44e1ac
authored
Nov 24, 2021
by
George Koltsov
Committed by
Bob Van Landuyt
Nov 24, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add badges to Project Migration
parent
ab8d113a
Changes
13
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
231 additions
and
28 deletions
+231
-28
app/models/bulk_imports/entity.rb
app/models/bulk_imports/entity.rb
+13
-1
ee/spec/lib/ee/bulk_imports/groups/stage_spec.rb
ee/spec/lib/ee/bulk_imports/groups/stage_spec.rb
+1
-1
ee/spec/lib/ee/bulk_imports/projects/stage_spec.rb
ee/spec/lib/ee/bulk_imports/projects/stage_spec.rb
+1
-0
lib/bulk_imports/common/pipelines/badges_pipeline.rb
lib/bulk_imports/common/pipelines/badges_pipeline.rb
+44
-0
lib/bulk_imports/common/rest/get_badges_query.rb
lib/bulk_imports/common/rest/get_badges_query.rb
+3
-2
lib/bulk_imports/groups/stage.rb
lib/bulk_imports/groups/stage.rb
+1
-1
lib/bulk_imports/projects/stage.rb
lib/bulk_imports/projects/stage.rb
+4
-0
spec/lib/bulk_imports/common/pipelines/badges_pipeline_spec.rb
...lib/bulk_imports/common/pipelines/badges_pipeline_spec.rb
+96
-0
spec/lib/bulk_imports/common/rest/get_badges_query_spec.rb
spec/lib/bulk_imports/common/rest/get_badges_query_spec.rb
+36
-0
spec/lib/bulk_imports/groups/rest/get_badges_query_spec.rb
spec/lib/bulk_imports/groups/rest/get_badges_query_spec.rb
+0
-22
spec/lib/bulk_imports/groups/stage_spec.rb
spec/lib/bulk_imports/groups/stage_spec.rb
+1
-1
spec/lib/bulk_imports/projects/stage_spec.rb
spec/lib/bulk_imports/projects/stage_spec.rb
+1
-0
spec/models/bulk_imports/entity_spec.rb
spec/models/bulk_imports/entity_spec.rb
+30
-0
No files found.
app/models/bulk_imports/entity.rb
View file @
6c44e1ac
...
...
@@ -104,8 +104,12 @@ class BulkImports::Entity < ApplicationRecord
end
end
def
entity_type
source_type
.
gsub
(
'_entity'
,
''
)
end
def
pluralized_name
source_type
.
gsub
(
'_entity'
,
''
)
.
pluralize
entity_type
.
pluralize
end
def
export_relations_url_path
...
...
@@ -116,6 +120,14 @@ class BulkImports::Entity < ApplicationRecord
"
#{
export_relations_url_path
}
/download?relation=
#{
relation
}
"
end
def
project?
source_type
==
'project_entity'
end
def
group?
source_type
==
'group_entity'
end
private
def
validate_parent_is_a_group
...
...
ee/spec/lib/ee/bulk_imports/groups/stage_spec.rb
View file @
6c44e1ac
...
...
@@ -11,7 +11,7 @@ RSpec.describe BulkImports::Groups::Stage do
[
1
,
BulkImports
::
Groups
::
Pipelines
::
MembersPipeline
],
[
1
,
BulkImports
::
Common
::
Pipelines
::
LabelsPipeline
],
[
1
,
BulkImports
::
Common
::
Pipelines
::
MilestonesPipeline
],
[
1
,
BulkImports
::
Groups
::
Pipelines
::
BadgesPipeline
],
[
1
,
BulkImports
::
Common
::
Pipelines
::
BadgesPipeline
],
[
1
,
BulkImports
::
Groups
::
Pipelines
::
IterationsPipeline
],
[
1
,
BulkImports
::
Groups
::
Pipelines
::
ProjectEntitiesPipeline
],
[
2
,
BulkImports
::
Common
::
Pipelines
::
BoardsPipeline
],
...
...
ee/spec/lib/ee/bulk_imports/projects/stage_spec.rb
View file @
6c44e1ac
...
...
@@ -9,6 +9,7 @@ RSpec.describe BulkImports::Projects::Stage do
[
1
,
BulkImports
::
Projects
::
Pipelines
::
RepositoryPipeline
],
[
2
,
BulkImports
::
Common
::
Pipelines
::
LabelsPipeline
],
[
2
,
BulkImports
::
Common
::
Pipelines
::
MilestonesPipeline
],
[
2
,
BulkImports
::
Common
::
Pipelines
::
BadgesPipeline
],
[
3
,
BulkImports
::
Projects
::
Pipelines
::
IssuesPipeline
],
[
3
,
BulkImports
::
Projects
::
Pipelines
::
SnippetsPipeline
],
[
4
,
BulkImports
::
Common
::
Pipelines
::
BoardsPipeline
],
...
...
lib/bulk_imports/
groups
/pipelines/badges_pipeline.rb
→
lib/bulk_imports/
common
/pipelines/badges_pipeline.rb
View file @
6c44e1ac
# frozen_string_literal: true
module
BulkImports
module
Groups
module
Common
module
Pipelines
class
BadgesPipeline
include
Pipeline
extractor
BulkImports
::
Common
::
Extractors
::
RestExtractor
,
query:
BulkImports
::
Groups
::
Rest
::
GetBadgesQuery
query:
BulkImports
::
Common
::
Rest
::
GetBadgesQuery
transformer
Common
::
Transformers
::
ProhibitedAttributesTransformer
def
transform
(
_
,
data
)
def
transform
(
context
,
data
)
return
if
data
.
blank?
# Project badges API returns badges of both group and project kind. To avoid creation of duplicates for the group we skip group badges when it's a project.
return
if
context
.
entity
.
project?
&&
group_badge?
(
data
)
{
name:
data
[
'name'
],
...
...
@@ -24,7 +26,17 @@ module BulkImports
def
load
(
context
,
data
)
return
if
data
.
blank?
context
.
group
.
badges
.
create!
(
data
)
if
context
.
entity
.
project?
context
.
portable
.
project_badges
.
create!
(
data
)
else
context
.
portable
.
badges
.
create!
(
data
)
end
end
private
def
group_badge?
(
data
)
data
[
'kind'
]
==
'group'
end
end
end
...
...
lib/bulk_imports/
groups
/rest/get_badges_query.rb
→
lib/bulk_imports/
common
/rest/get_badges_query.rb
View file @
6c44e1ac
# frozen_string_literal: true
module
BulkImports
module
Groups
module
Common
module
Rest
module
GetBadgesQuery
extend
self
def
to_h
(
context
)
resource
=
context
.
entity
.
pluralized_name
encoded_full_path
=
ERB
::
Util
.
url_encode
(
context
.
entity
.
source_full_path
)
{
resource:
[
'groups'
,
encoded_full_path
,
'badges'
].
join
(
'/'
),
resource:
[
resource
,
encoded_full_path
,
'badges'
].
join
(
'/'
),
query:
{
page:
context
.
tracker
.
next_page
}
...
...
lib/bulk_imports/groups/stage.rb
View file @
6c44e1ac
...
...
@@ -32,7 +32,7 @@ module BulkImports
stage:
1
},
badges:
{
pipeline:
BulkImports
::
Groups
::
Pipelines
::
BadgesPipeline
,
pipeline:
BulkImports
::
Common
::
Pipelines
::
BadgesPipeline
,
stage:
1
},
boards:
{
...
...
lib/bulk_imports/projects/stage.rb
View file @
6c44e1ac
...
...
@@ -23,6 +23,10 @@ module BulkImports
pipeline:
BulkImports
::
Common
::
Pipelines
::
MilestonesPipeline
,
stage:
2
},
badges:
{
pipeline:
BulkImports
::
Common
::
Pipelines
::
BadgesPipeline
,
stage:
2
},
issues:
{
pipeline:
BulkImports
::
Projects
::
Pipelines
::
IssuesPipeline
,
stage:
3
...
...
spec/lib/bulk_imports/
groups
/pipelines/badges_pipeline_spec.rb
→
spec/lib/bulk_imports/
common
/pipelines/badges_pipeline_spec.rb
View file @
6c44e1ac
...
...
@@ -2,37 +2,29 @@
require
'spec_helper'
RSpec
.
describe
BulkImports
::
Groups
::
Pipelines
::
BadgesPipeline
do
RSpec
.
describe
BulkImports
::
Common
::
Pipelines
::
BadgesPipeline
do
let_it_be
(
:user
)
{
create
(
:user
)
}
let_it_be
(
:group
)
{
create
(
:group
)
}
let_it_be
(
:project
)
{
create
(
:project
)
}
let_it_be
(
:entity
)
do
create
(
:bulk_import_entity
,
source_full_path:
'source/full/path'
,
destination_name:
'My Destination Group'
,
destination_namespace:
group
.
full_path
,
group:
group
)
end
let_it_be
(
:tracker
)
{
create
(
:bulk_import_tracker
,
entity:
entity
)
}
let_it_be
(
:context
)
{
BulkImports
::
Pipeline
::
Context
.
new
(
tracker
)
}
let
(
:entity
)
{
create
(
:bulk_import_entity
,
group:
group
)
}
let
(
:tracker
)
{
create
(
:bulk_import_tracker
,
entity:
entity
)
}
let
(
:context
)
{
BulkImports
::
Pipeline
::
Context
.
new
(
tracker
)
}
subject
{
described_class
.
new
(
context
)
}
subject
(
:pipeline
)
{
described_class
.
new
(
context
)
}
describe
'#run'
do
it
'imports a group badge'
do
first_page
=
extracted_data
(
has_next_page:
true
)
last_page
=
extracted_data
(
name:
'badge2'
)
let
(
:first_page
)
{
extracted_data
(
has_next_page:
true
)
}
let
(
:last_page
)
{
extracted_data
(
name:
'badge2'
)
}
before
do
allow_next_instance_of
(
BulkImports
::
Common
::
Extractors
::
RestExtractor
)
do
|
extractor
|
allow
(
extractor
)
.
to
receive
(
:extract
)
.
and_return
(
first_page
,
last_page
)
allow
(
extractor
).
to
receive
(
:extract
).
and_return
(
first_page
,
last_page
)
end
end
expect
{
subject
.
run
}.
to
change
(
Badge
,
:count
).
by
(
2
)
it
'imports a group badge'
do
expect
{
pipeline
.
run
}.
to
change
(
Badge
,
:count
).
by
(
2
)
badge
=
group
.
badges
.
last
...
...
@@ -41,19 +33,20 @@ RSpec.describe BulkImports::Groups::Pipelines::BadgesPipeline do
expect
(
badge
.
image_url
).
to
eq
(
badge_data
[
'image_url'
])
end
describe
'#load'
do
it
'creates a badge'
do
expect
{
subject
.
load
(
context
,
badge_data
)
}.
to
change
(
Badge
,
:count
).
by
(
1
)
context
'when project entity'
do
let
(
:first_page
)
{
extracted_data
(
has_next_page:
true
)
}
let
(
:last_page
)
{
extracted_data
(
name:
'badge2'
,
kind:
'project'
)
}
let
(
:entity
)
{
create
(
:bulk_import_entity
,
:project_entity
,
project:
project
)
}
badge
=
group
.
badges
.
first
it
'imports a project badge & skips group badge'
do
expect
{
pipeline
.
run
}.
to
change
(
Badge
,
:count
).
by
(
1
)
badge_data
.
each
do
|
key
,
value
|
expect
(
badge
[
key
]).
to
eq
(
value
)
end
end
badge
=
project
.
badges
.
last
it
'does nothing when the data is blank'
do
expect
{
subject
.
load
(
context
,
nil
)
}.
not_to
change
(
Badge
,
:count
)
expect
(
badge
.
name
).
to
eq
(
'badge2'
)
expect
(
badge
.
link_url
).
to
eq
(
badge_data
[
'link_url'
])
expect
(
badge
.
image_url
).
to
eq
(
badge_data
[
'image_url'
])
expect
(
badge
.
type
).
to
eq
(
'ProjectBadge'
)
end
end
...
...
@@ -72,45 +65,32 @@ RSpec.describe BulkImports::Groups::Pipelines::BadgesPipeline do
expect
(
subject
.
transform
(
context
,
nil
)).
to
be_nil
end
end
end
describe
'pipeline parts'
do
it
{
expect
(
described_class
).
to
include_module
(
BulkImports
::
Pipeline
)
}
it
{
expect
(
described_class
).
to
include_module
(
BulkImports
::
Pipeline
::
Runner
)
}
it
'has extractors'
do
expect
(
described_class
.
get_extractor
)
.
to
eq
(
klass:
BulkImports
::
Common
::
Extractors
::
RestExtractor
,
options:
{
query:
BulkImports
::
Groups
::
Rest
::
GetBadgesQuery
}
)
end
context
'when project entity & group badge'
do
let
(
:entity
)
{
create
(
:bulk_import_entity
,
:project_entity
,
project:
project
)
}
it
'has transformers'
do
expect
(
described_class
.
transformers
)
.
to
contain_exactly
(
{
klass:
BulkImports
::
Common
::
Transformers
::
ProhibitedAttributesTransformer
,
options:
nil
}
)
it
'returns'
do
expect
(
subject
.
transform
(
context
,
{
'name'
=>
'test'
,
'kind'
=>
'group'
})).
to
be_nil
end
end
end
def
badge_data
(
name
=
'badge'
)
def
badge_data
(
name
=
'badge'
,
kind
=
'group'
)
{
'name'
=>
name
,
'link_url'
=>
'https://gitlab.example.com'
,
'image_url'
=>
'https://gitlab.example.com/image.png'
'image_url'
=>
'https://gitlab.example.com/image.png'
,
'kind'
=>
kind
}
end
def
extracted_data
(
name:
'badge'
,
has_next_page:
false
)
def
extracted_data
(
name:
'badge'
,
kind:
'group'
,
has_next_page:
false
)
page_info
=
{
'has_next_page'
=>
has_next_page
,
'next_page'
=>
has_next_page
?
'2'
:
nil
}
BulkImports
::
Pipeline
::
ExtractedData
.
new
(
data:
[
badge_data
(
name
)],
page_info:
page_info
)
BulkImports
::
Pipeline
::
ExtractedData
.
new
(
data:
[
badge_data
(
name
,
kind
)],
page_info:
page_info
)
end
end
end
spec/lib/bulk_imports/common/rest/get_badges_query_spec.rb
0 → 100644
View file @
6c44e1ac
# frozen_string_literal: true
require
'spec_helper'
RSpec
.
describe
BulkImports
::
Common
::
Rest
::
GetBadgesQuery
do
describe
'.to_h'
do
shared_examples
'resource and page info query'
do
let
(
:tracker
)
{
create
(
:bulk_import_tracker
,
entity:
entity
)
}
let
(
:context
)
{
BulkImports
::
Pipeline
::
Context
.
new
(
tracker
)
}
let
(
:encoded_full_path
)
{
ERB
::
Util
.
url_encode
(
entity
.
source_full_path
)
}
it
'returns correct query and page info'
do
expected
=
{
resource:
[
entity
.
pluralized_name
,
encoded_full_path
,
'badges'
].
join
(
'/'
),
query:
{
page:
context
.
tracker
.
next_page
}
}
expect
(
described_class
.
to_h
(
context
)).
to
eq
(
expected
)
end
end
context
'when entity is group'
do
let
(
:entity
)
{
create
(
:bulk_import_entity
)
}
include_examples
'resource and page info query'
end
context
'when entity is project'
do
let
(
:entity
)
{
create
(
:bulk_import_entity
,
:project_entity
)
}
include_examples
'resource and page info query'
end
end
end
spec/lib/bulk_imports/groups/rest/get_badges_query_spec.rb
deleted
100644 → 0
View file @
ab8d113a
# frozen_string_literal: true
require
'spec_helper'
RSpec
.
describe
BulkImports
::
Groups
::
Rest
::
GetBadgesQuery
do
describe
'.to_h'
do
it
'returns query resource and page info'
do
entity
=
create
(
:bulk_import_entity
)
tracker
=
create
(
:bulk_import_tracker
,
entity:
entity
)
context
=
BulkImports
::
Pipeline
::
Context
.
new
(
tracker
)
encoded_full_path
=
ERB
::
Util
.
url_encode
(
entity
.
source_full_path
)
expected
=
{
resource:
[
'groups'
,
encoded_full_path
,
'badges'
].
join
(
'/'
),
query:
{
page:
context
.
tracker
.
next_page
}
}
expect
(
described_class
.
to_h
(
context
)).
to
eq
(
expected
)
end
end
end
spec/lib/bulk_imports/groups/stage_spec.rb
View file @
6c44e1ac
...
...
@@ -13,7 +13,7 @@ RSpec.describe BulkImports::Groups::Stage do
[
1
,
BulkImports
::
Groups
::
Pipelines
::
MembersPipeline
],
[
1
,
BulkImports
::
Common
::
Pipelines
::
LabelsPipeline
],
[
1
,
BulkImports
::
Common
::
Pipelines
::
MilestonesPipeline
],
[
1
,
BulkImports
::
Groups
::
Pipelines
::
BadgesPipeline
],
[
1
,
BulkImports
::
Common
::
Pipelines
::
BadgesPipeline
],
[
2
,
BulkImports
::
Common
::
Pipelines
::
BoardsPipeline
]
]
end
...
...
spec/lib/bulk_imports/projects/stage_spec.rb
View file @
6c44e1ac
...
...
@@ -11,6 +11,7 @@ RSpec.describe BulkImports::Projects::Stage do
[
1
,
BulkImports
::
Projects
::
Pipelines
::
RepositoryPipeline
],
[
2
,
BulkImports
::
Common
::
Pipelines
::
LabelsPipeline
],
[
2
,
BulkImports
::
Common
::
Pipelines
::
MilestonesPipeline
],
[
2
,
BulkImports
::
Common
::
Pipelines
::
BadgesPipeline
],
[
3
,
BulkImports
::
Projects
::
Pipelines
::
IssuesPipeline
],
[
3
,
BulkImports
::
Projects
::
Pipelines
::
SnippetsPipeline
],
[
4
,
BulkImports
::
Common
::
Pipelines
::
BoardsPipeline
],
...
...
spec/models/bulk_imports/entity_spec.rb
View file @
6c44e1ac
...
...
@@ -252,4 +252,34 @@ RSpec.describe BulkImports::Entity, type: :model do
.
to
eq
(
"/groups/
#{
entity
.
encoded_source_full_path
}
/export_relations/download?relation=test"
)
end
end
describe
'#entity_type'
do
it
'returns entity type'
do
group_entity
=
build
(
:bulk_import_entity
)
project_entity
=
build
(
:bulk_import_entity
,
:project_entity
)
expect
(
group_entity
.
entity_type
).
to
eq
(
'group'
)
expect
(
project_entity
.
entity_type
).
to
eq
(
'project'
)
end
end
describe
'#project?'
do
it
'returns true if project entity'
do
group_entity
=
build
(
:bulk_import_entity
)
project_entity
=
build
(
:bulk_import_entity
,
:project_entity
)
expect
(
group_entity
.
project?
).
to
eq
(
false
)
expect
(
project_entity
.
project?
).
to
eq
(
true
)
end
end
describe
'#group?'
do
it
'returns true if group entity'
do
group_entity
=
build
(
:bulk_import_entity
)
project_entity
=
build
(
:bulk_import_entity
,
:project_entity
)
expect
(
group_entity
.
group?
).
to
eq
(
true
)
expect
(
project_entity
.
group?
).
to
eq
(
false
)
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