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
9ee6a1c3
Commit
9ee6a1c3
authored
May 12, 2021
by
George Koltsov
Committed by
Matthias Käppler
May 12, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rename `exportable` variables to `portable` within `BulkImports` namespace
parent
994b2e59
Changes
15
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
110 additions
and
74 deletions
+110
-74
app/models/bulk_imports/export.rb
app/models/bulk_imports/export.rb
+8
-17
app/models/bulk_imports/file_transfer.rb
app/models/bulk_imports/file_transfer.rb
+20
-0
app/models/bulk_imports/file_transfer/base_config.rb
app/models/bulk_imports/file_transfer/base_config.rb
+12
-12
app/models/bulk_imports/file_transfer/group_config.rb
app/models/bulk_imports/file_transfer/group_config.rb
+2
-2
app/models/bulk_imports/file_transfer/project_config.rb
app/models/bulk_imports/file_transfer/project_config.rb
+2
-2
app/services/bulk_imports/export_service.rb
app/services/bulk_imports/export_service.rb
+5
-5
app/services/bulk_imports/relation_export_service.rb
app/services/bulk_imports/relation_export_service.rb
+15
-15
app/workers/bulk_imports/relation_export_worker.rb
app/workers/bulk_imports/relation_export_worker.rb
+5
-5
lib/api/group_export.rb
lib/api/group_export.rb
+1
-1
spec/models/bulk_imports/export_spec.rb
spec/models/bulk_imports/export_spec.rb
+5
-5
spec/models/bulk_imports/file_transfer/group_config_spec.rb
spec/models/bulk_imports/file_transfer/group_config_spec.rb
+3
-3
spec/models/bulk_imports/file_transfer/project_config_spec.rb
.../models/bulk_imports/file_transfer/project_config_spec.rb
+3
-3
spec/models/bulk_imports/file_transfer_spec.rb
spec/models/bulk_imports/file_transfer_spec.rb
+25
-0
spec/services/bulk_imports/export_service_spec.rb
spec/services/bulk_imports/export_service_spec.rb
+3
-3
spec/services/bulk_imports/relation_export_service_spec.rb
spec/services/bulk_imports/relation_export_service_spec.rb
+1
-1
No files found.
app/models/bulk_imports/export.rb
View file @
9ee6a1c3
...
...
@@ -15,7 +15,7 @@ module BulkImports
validates
:group
,
presence:
true
,
unless: :project
validates
:relation
,
:status
,
presence:
true
validate
:
ex
portable_relation?
validate
:portable_relation?
state_machine
:status
,
initial: :started
do
state
:started
,
value:
0
...
...
@@ -36,34 +36,25 @@ module BulkImports
end
end
def
self
.
config
(
exportable
)
case
exportable
when
::
Project
Exports
::
ProjectConfig
.
new
(
exportable
)
when
::
Group
Exports
::
GroupConfig
.
new
(
exportable
)
end
end
def
exportable_relation?
return
unless
exportable
def
portable_relation?
return
unless
portable
errors
.
add
(
:relation
,
'Unsupported
exportable relation'
)
unless
config
.
ex
portable_relations
.
include?
(
relation
)
errors
.
add
(
:relation
,
'Unsupported
portable relation'
)
unless
config
.
portable_relations
.
include?
(
relation
)
end
def
ex
portable
strong_memoize
(
:
ex
portable
)
do
def
portable
strong_memoize
(
:portable
)
do
project
||
group
end
end
def
relation_definition
config
.
ex
portable_tree
[
:include
].
find
{
|
include
|
include
[
relation
.
to_sym
]
}
config
.
portable_tree
[
:include
].
find
{
|
include
|
include
[
relation
.
to_sym
]
}
end
def
config
strong_memoize
(
:config
)
do
self
.
class
.
config
(
ex
portable
)
FileTransfer
.
config_for
(
portable
)
end
end
end
...
...
app/models/bulk_imports/file_transfer.rb
0 → 100644
View file @
9ee6a1c3
# frozen_string_literal: true
module
BulkImports
module
FileTransfer
extend
self
UnsupportedObjectType
=
Class
.
new
(
StandardError
)
def
config_for
(
portable
)
case
portable
when
::
Project
FileTransfer
::
ProjectConfig
.
new
(
portable
)
when
::
Group
FileTransfer
::
GroupConfig
.
new
(
portable
)
else
raise
(
UnsupportedObjectType
,
"Unsupported object type:
#{
portable
.
class
}
"
)
end
end
end
end
app/models/bulk_imports/
exports
/base_config.rb
→
app/models/bulk_imports/
file_transfer
/base_config.rb
View file @
9ee6a1c3
# frozen_string_literal: true
module
BulkImports
module
Exports
module
FileTransfer
class
BaseConfig
include
Gitlab
::
Utils
::
StrongMemoize
def
initialize
(
ex
portable
)
@
exportable
=
ex
portable
def
initialize
(
portable
)
@
portable
=
portable
end
def
ex
portable_tree
attributes_finder
.
find_root
(
ex
portable_class_sym
)
def
portable_tree
attributes_finder
.
find_root
(
portable_class_sym
)
end
def
export_path
...
...
@@ -21,13 +21,13 @@ module BulkImports
end
end
def
ex
portable_relations
import_export_config
.
dig
(
:tree
,
ex
portable_class_sym
).
keys
.
map
(
&
:to_s
)
def
portable_relations
import_export_config
.
dig
(
:tree
,
portable_class_sym
).
keys
.
map
(
&
:to_s
)
end
private
attr_reader
:
ex
portable
attr_reader
:portable
def
attributes_finder
strong_memoize
(
:attributes_finder
)
do
...
...
@@ -39,12 +39,12 @@ module BulkImports
::
Gitlab
::
ImportExport
::
Config
.
new
(
config:
import_export_yaml
).
to_h
end
def
ex
portable_class
@
exportable_class
||=
ex
portable
.
class
def
portable_class
@
portable_class
||=
portable
.
class
end
def
ex
portable_class_sym
@
exportable_class_sym
||=
exportable_class
.
to_s
.
downcas
e
.
to_sym
def
portable_class_sym
@
portable_class_sym
||=
portable_class
.
to_s
.
demodulize
.
underscor
e
.
to_sym
end
def
import_export_yaml
...
...
app/models/bulk_imports/
exports
/group_config.rb
→
app/models/bulk_imports/
file_transfer
/group_config.rb
View file @
9ee6a1c3
# frozen_string_literal: true
module
BulkImports
module
Exports
module
FileTransfer
class
GroupConfig
<
BaseConfig
def
base_export_path
ex
portable
.
full_path
portable
.
full_path
end
def
import_export_yaml
...
...
app/models/bulk_imports/
exports
/project_config.rb
→
app/models/bulk_imports/
file_transfer
/project_config.rb
View file @
9ee6a1c3
# frozen_string_literal: true
module
BulkImports
module
Exports
module
FileTransfer
class
ProjectConfig
<
BaseConfig
def
base_export_path
ex
portable
.
disk_path
portable
.
disk_path
end
def
import_export_yaml
...
...
app/services/bulk_imports/export_service.rb
View file @
9ee6a1c3
...
...
@@ -2,14 +2,14 @@
module
BulkImports
class
ExportService
def
initialize
(
ex
portable
:,
user
:)
@
exportable
=
ex
portable
def
initialize
(
portable
:,
user
:)
@
portable
=
portable
@current_user
=
user
end
def
execute
Export
.
config
(
exportable
).
ex
portable_relations
.
each
do
|
relation
|
RelationExportWorker
.
perform_async
(
current_user
.
id
,
exportable
.
id
,
ex
portable
.
class
.
name
,
relation
)
FileTransfer
.
config_for
(
portable
).
portable_relations
.
each
do
|
relation
|
RelationExportWorker
.
perform_async
(
current_user
.
id
,
portable
.
id
,
portable
.
class
.
name
,
relation
)
end
ServiceResponse
.
success
...
...
@@ -22,6 +22,6 @@ module BulkImports
private
attr_reader
:
ex
portable
,
:current_user
attr_reader
:portable
,
:current_user
end
end
app/services/bulk_imports/relation_export_service.rb
View file @
9ee6a1c3
...
...
@@ -4,9 +4,9 @@ module BulkImports
class
RelationExportService
include
Gitlab
::
ImportExport
::
CommandLineUtil
def
initialize
(
user
,
ex
portable
,
relation
,
jid
)
def
initialize
(
user
,
portable
,
relation
,
jid
)
@user
=
user
@
exportable
=
ex
portable
@
portable
=
portable
@relation
=
relation
@jid
=
jid
end
...
...
@@ -22,28 +22,28 @@ module BulkImports
private
attr_reader
:user
,
:
ex
portable
,
:relation
,
:jid
attr_reader
:user
,
:portable
,
:relation
,
:jid
def
find_or_create_export!
validate_user_permissions!
export
=
ex
portable
.
bulk_import_exports
.
safe_find_or_create_by!
(
relation:
relation
)
export
=
portable
.
bulk_import_exports
.
safe_find_or_create_by!
(
relation:
relation
)
export
.
update!
(
status_event:
'start'
,
jid:
jid
)
yield
export
export
.
update!
(
status_event:
'finish'
,
error:
nil
)
rescue
StandardError
=>
e
Gitlab
::
ErrorTracking
.
track_exception
(
e
,
exportable_id:
exportable
.
id
,
exportable_type:
ex
portable
.
class
.
name
)
Gitlab
::
ErrorTracking
.
track_exception
(
e
,
portable_id:
portable
.
id
,
portable_type:
portable
.
class
.
name
)
export
&
.
update
(
status_event:
'fail_op'
,
error:
e
.
class
)
end
def
validate_user_permissions!
ability
=
"admin_
#{
ex
portable
.
to_ability_name
}
"
ability
=
"admin_
#{
portable
.
to_ability_name
}
"
user
.
can?
(
ability
,
ex
portable
)
||
raise
(
::
Gitlab
::
ImportExport
::
Error
.
permission_error
(
user
,
ex
portable
))
user
.
can?
(
ability
,
portable
)
||
raise
(
::
Gitlab
::
ImportExport
::
Error
.
permission_error
(
user
,
portable
))
end
def
remove_existing_export_file!
(
export
)
...
...
@@ -72,23 +72,23 @@ module BulkImports
upload
.
save!
end
def
export_
config
@
export_config
||=
Export
.
config
(
ex
portable
)
def
config
@
config
||=
FileTransfer
.
config_for
(
portable
)
end
def
export_path
@export_path
||=
export_
config
.
export_path
@export_path
||=
config
.
export_path
end
def
ex
portable_tree
@
exportable_tree
||=
export_config
.
ex
portable_tree
def
portable_tree
@
portable_tree
||=
config
.
portable_tree
end
# rubocop: disable CodeReuse/Serializer
def
serializer
@serializer
||=
::
Gitlab
::
ImportExport
::
JSON
::
StreamingSerializer
.
new
(
ex
portable
,
ex
portable_tree
,
portable
,
portable_tree
,
json_writer
,
exportable_path:
''
)
...
...
app/workers/bulk_imports/relation_export_worker.rb
View file @
9ee6a1c3
...
...
@@ -11,17 +11,17 @@ module BulkImports
tags
:exclude_from_kubernetes
sidekiq_options
status_expiration:
StuckExportJobsWorker
::
EXPORT_JOBS_EXPIRATION
def
perform
(
user_id
,
exportable_id
,
ex
portable_class
,
relation
)
def
perform
(
user_id
,
portable_id
,
portable_class
,
relation
)
user
=
User
.
find
(
user_id
)
exportable
=
exportable
(
exportable_id
,
ex
portable_class
)
portable
=
portable
(
portable_id
,
portable_class
)
RelationExportService
.
new
(
user
,
ex
portable
,
relation
,
jid
).
execute
RelationExportService
.
new
(
user
,
portable
,
relation
,
jid
).
execute
end
private
def
exportable
(
exportable_id
,
ex
portable_class
)
exportable_class
.
classify
.
constantize
.
find
(
ex
portable_id
)
def
portable
(
portable_id
,
portable_class
)
portable_class
.
classify
.
constantize
.
find
(
portable_id
)
end
end
end
lib/api/group_export.rb
View file @
9ee6a1c3
...
...
@@ -48,7 +48,7 @@ module API
detail
'This feature was introduced in GitLab 13.12'
end
post
':id/export_relations'
do
response
=
::
BulkImports
::
ExportService
.
new
(
ex
portable:
user_group
,
user:
current_user
).
execute
response
=
::
BulkImports
::
ExportService
.
new
(
portable:
user_group
,
user:
current_user
).
execute
if
response
.
success?
accepted!
...
...
spec/models/bulk_imports/export_spec.rb
View file @
9ee6a1c3
...
...
@@ -47,12 +47,12 @@ RSpec.describe BulkImports::Export, type: :model do
end
end
describe
'#
ex
portable'
do
describe
'#portable'
do
context
'when associated with project'
do
it
'returns project'
do
export
=
create
(
:bulk_import_export
,
project:
create
(
:project
),
group:
nil
)
expect
(
export
.
ex
portable
).
to
be_instance_of
(
Project
)
expect
(
export
.
portable
).
to
be_instance_of
(
Project
)
end
end
...
...
@@ -60,7 +60,7 @@ RSpec.describe BulkImports::Export, type: :model do
it
'returns group'
do
export
=
create
(
:bulk_import_export
)
expect
(
export
.
ex
portable
).
to
be_instance_of
(
Group
)
expect
(
export
.
portable
).
to
be_instance_of
(
Group
)
end
end
end
...
...
@@ -70,7 +70,7 @@ RSpec.describe BulkImports::Export, type: :model do
it
'returns project config'
do
export
=
create
(
:bulk_import_export
,
project:
create
(
:project
),
group:
nil
)
expect
(
export
.
config
).
to
be_instance_of
(
BulkImports
::
Exports
::
ProjectConfig
)
expect
(
export
.
config
).
to
be_instance_of
(
BulkImports
::
FileTransfer
::
ProjectConfig
)
end
end
...
...
@@ -78,7 +78,7 @@ RSpec.describe BulkImports::Export, type: :model do
it
'returns group config'
do
export
=
create
(
:bulk_import_export
)
expect
(
export
.
config
).
to
be_instance_of
(
BulkImports
::
Exports
::
GroupConfig
)
expect
(
export
.
config
).
to
be_instance_of
(
BulkImports
::
FileTransfer
::
GroupConfig
)
end
end
end
...
...
spec/models/bulk_imports/
exports
/group_config_spec.rb
→
spec/models/bulk_imports/
file_transfer
/group_config_spec.rb
View file @
9ee6a1c3
...
...
@@ -2,7 +2,7 @@
require
'spec_helper'
RSpec
.
describe
BulkImports
::
Exports
::
GroupConfig
do
RSpec
.
describe
BulkImports
::
FileTransfer
::
GroupConfig
do
let_it_be
(
:exportable
)
{
create
(
:group
)
}
let_it_be
(
:hex
)
{
'123'
}
...
...
@@ -18,7 +18,7 @@ RSpec.describe BulkImports::Exports::GroupConfig do
expect
(
finder
).
to
receive
(
:find_root
).
with
(
:group
).
and_call_original
end
expect
(
subject
.
ex
portable_tree
).
not_to
be_empty
expect
(
subject
.
portable_tree
).
not_to
be_empty
end
end
...
...
@@ -32,7 +32,7 @@ RSpec.describe BulkImports::Exports::GroupConfig do
describe
'#exportable_relations'
do
it
'returns a list of top level exportable relations'
do
expect
(
subject
.
ex
portable_relations
).
to
include
(
'milestones'
,
'badges'
,
'boards'
,
'labels'
)
expect
(
subject
.
portable_relations
).
to
include
(
'milestones'
,
'badges'
,
'boards'
,
'labels'
)
end
end
end
spec/models/bulk_imports/
exports
/project_config_spec.rb
→
spec/models/bulk_imports/
file_transfer
/project_config_spec.rb
View file @
9ee6a1c3
...
...
@@ -2,7 +2,7 @@
require
'spec_helper'
RSpec
.
describe
BulkImports
::
Exports
::
ProjectConfig
do
RSpec
.
describe
BulkImports
::
FileTransfer
::
ProjectConfig
do
let_it_be
(
:exportable
)
{
create
(
:project
)
}
let_it_be
(
:hex
)
{
'123'
}
...
...
@@ -18,7 +18,7 @@ RSpec.describe BulkImports::Exports::ProjectConfig do
expect
(
finder
).
to
receive
(
:find_root
).
with
(
:project
).
and_call_original
end
expect
(
subject
.
ex
portable_tree
).
not_to
be_empty
expect
(
subject
.
portable_tree
).
not_to
be_empty
end
end
...
...
@@ -32,7 +32,7 @@ RSpec.describe BulkImports::Exports::ProjectConfig do
describe
'#exportable_relations'
do
it
'returns a list of top level exportable relations'
do
expect
(
subject
.
ex
portable_relations
).
to
include
(
'issues'
,
'labels'
,
'milestones'
,
'merge_requests'
)
expect
(
subject
.
portable_relations
).
to
include
(
'issues'
,
'labels'
,
'milestones'
,
'merge_requests'
)
end
end
end
spec/models/bulk_imports/file_transfer_spec.rb
0 → 100644
View file @
9ee6a1c3
# frozen_string_literal: true
require
'spec_helper'
RSpec
.
describe
BulkImports
::
FileTransfer
do
describe
'.config_for'
do
context
'when portable is group'
do
it
'returns group config'
do
expect
(
described_class
.
config_for
(
build
(
:group
))).
to
be_instance_of
(
BulkImports
::
FileTransfer
::
GroupConfig
)
end
end
context
'when portable is project'
do
it
'returns project config'
do
expect
(
described_class
.
config_for
(
build
(
:project
))).
to
be_instance_of
(
BulkImports
::
FileTransfer
::
ProjectConfig
)
end
end
context
'when portable is unsupported'
do
it
'raises an error'
do
expect
{
described_class
.
config_for
(
nil
)
}.
to
raise_error
(
BulkImports
::
FileTransfer
::
UnsupportedObjectType
)
end
end
end
end
spec/services/bulk_imports/export_service_spec.rb
View file @
9ee6a1c3
...
...
@@ -10,12 +10,12 @@ RSpec.describe BulkImports::ExportService do
group
.
add_owner
(
user
)
end
subject
{
described_class
.
new
(
ex
portable:
group
,
user:
user
)
}
subject
{
described_class
.
new
(
portable:
group
,
user:
user
)
}
describe
'#execute'
do
it
'schedules RelationExportWorker for each top level relation'
do
expect
(
subject
).
to
receive
(
:execute
).
and_return
(
ServiceResponse
.
success
).
and_call_original
top_level_relations
=
BulkImports
::
Export
.
config
(
group
).
ex
portable_relations
top_level_relations
=
BulkImports
::
FileTransfer
.
config_for
(
group
).
portable_relations
top_level_relations
.
each
do
|
relation
|
expect
(
BulkImports
::
RelationExportWorker
)
...
...
@@ -28,7 +28,7 @@ RSpec.describe BulkImports::ExportService do
context
'when exception occurs'
do
it
'does not schedule RelationExportWorker'
do
service
=
described_class
.
new
(
ex
portable:
nil
,
user:
user
)
service
=
described_class
.
new
(
portable:
nil
,
user:
user
)
expect
(
service
)
.
to
receive
(
:execute
)
...
...
spec/services/bulk_imports/relation_export_service_spec.rb
View file @
9ee6a1c3
...
...
@@ -77,7 +77,7 @@ RSpec.describe BulkImports::RelationExportService do
it
'tracks exception'
do
expect
(
Gitlab
::
ErrorTracking
)
.
to
receive
(
:track_exception
)
.
with
(
exception_class
,
exportable_id:
group
.
id
,
ex
portable_type:
group
.
class
.
name
)
.
with
(
exception_class
,
portable_id:
group
.
id
,
portable_type:
group
.
class
.
name
)
.
and_call_original
subject
.
execute
...
...
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