2021-07-05 08:08:33 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module API
|
|
|
|
class BulkImports < ::API::Base
|
|
|
|
include PaginationParams
|
|
|
|
|
|
|
|
feature_category :importers
|
2022-04-27 14:10:15 -04:00
|
|
|
urgency :low
|
2021-07-05 08:08:33 -04:00
|
|
|
|
|
|
|
helpers do
|
|
|
|
def bulk_imports
|
2021-07-22 17:09:40 -04:00
|
|
|
@bulk_imports ||= ::BulkImports::ImportsFinder.new(
|
|
|
|
user: current_user,
|
2022-03-30 02:09:34 -04:00
|
|
|
params: params
|
2021-07-22 17:09:40 -04:00
|
|
|
).execute
|
2021-07-05 08:08:33 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def bulk_import
|
|
|
|
@bulk_import ||= bulk_imports.find(params[:import_id])
|
|
|
|
end
|
|
|
|
|
|
|
|
def bulk_import_entities
|
2021-07-22 17:09:40 -04:00
|
|
|
@bulk_import_entities ||= ::BulkImports::EntitiesFinder.new(
|
|
|
|
user: current_user,
|
|
|
|
bulk_import: bulk_import,
|
2022-03-30 02:09:34 -04:00
|
|
|
params: params
|
2021-07-22 17:09:40 -04:00
|
|
|
).execute
|
2021-07-05 08:08:33 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def bulk_import_entity
|
|
|
|
@bulk_import_entity ||= bulk_import_entities.find(params[:entity_id])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-09-20 08:11:03 -04:00
|
|
|
before do
|
|
|
|
not_found! unless ::BulkImports::Features.enabled?
|
|
|
|
|
|
|
|
authenticate!
|
|
|
|
end
|
2021-07-05 08:08:33 -04:00
|
|
|
|
|
|
|
resource :bulk_imports do
|
2021-07-22 17:09:40 -04:00
|
|
|
desc 'Start a new GitLab Migration' do
|
|
|
|
detail 'This feature was introduced in GitLab 14.2.'
|
2022-10-13 23:10:15 -04:00
|
|
|
success Entities::BulkImport
|
2021-07-22 17:09:40 -04:00
|
|
|
end
|
|
|
|
params do
|
|
|
|
requires :configuration, type: Hash, desc: 'The source GitLab instance configuration' do
|
|
|
|
requires :url, type: String, desc: 'Source GitLab instance URL'
|
|
|
|
requires :access_token, type: String, desc: 'Access token to the source GitLab instance'
|
|
|
|
end
|
|
|
|
requires :entities, type: Array, desc: 'List of entities to import' do
|
2022-08-10 20:09:45 -04:00
|
|
|
requires :source_type,
|
|
|
|
type: String,
|
|
|
|
desc: 'Source entity type (only `group_entity` is supported)',
|
2021-07-22 17:09:40 -04:00
|
|
|
values: %w[group_entity]
|
|
|
|
requires :source_full_path, type: String, desc: 'Source full path of the entity to import'
|
|
|
|
requires :destination_namespace, type: String, desc: 'Destination namespace for the entity'
|
2022-07-21 08:10:03 -04:00
|
|
|
optional :destination_slug, type: String, desc: 'Destination slug for the entity'
|
2022-08-10 20:09:45 -04:00
|
|
|
optional :destination_name,
|
|
|
|
type: String,
|
2022-07-21 08:10:03 -04:00
|
|
|
desc: 'Deprecated: Use :destination_slug instead. Destination slug for the entity'
|
|
|
|
|
|
|
|
mutually_exclusive :destination_slug, :destination_name
|
|
|
|
at_least_one_of :destination_slug, :destination_name
|
2021-07-22 17:09:40 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
post do
|
2022-07-21 08:10:03 -04:00
|
|
|
params[:entities].each do |entity|
|
|
|
|
if entity[:destination_name]
|
|
|
|
entity[:destination_slug] ||= entity[:destination_name]
|
|
|
|
entity.delete(:destination_name)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-10-01 11:12:53 -04:00
|
|
|
response = ::BulkImports::CreateService.new(
|
2021-07-22 17:09:40 -04:00
|
|
|
current_user,
|
|
|
|
params[:entities],
|
|
|
|
url: params[:configuration][:url],
|
|
|
|
access_token: params[:configuration][:access_token]
|
|
|
|
).execute
|
|
|
|
|
|
|
|
if response.success?
|
|
|
|
present response.payload, with: Entities::BulkImport
|
|
|
|
else
|
|
|
|
render_api_error!(response.message, response.http_status)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-07-05 08:08:33 -04:00
|
|
|
desc 'List all GitLab Migrations' do
|
|
|
|
detail 'This feature was introduced in GitLab 14.1.'
|
2022-10-13 23:10:15 -04:00
|
|
|
success Entities::BulkImport
|
2021-07-05 08:08:33 -04:00
|
|
|
end
|
|
|
|
params do
|
|
|
|
use :pagination
|
2022-03-30 02:09:34 -04:00
|
|
|
optional :sort, type: String, values: %w[asc desc], default: 'desc',
|
2022-08-10 20:09:45 -04:00
|
|
|
desc: 'Return GitLab Migrations sorted in created by `asc` or `desc` order.'
|
2021-07-05 08:08:33 -04:00
|
|
|
optional :status, type: String, values: BulkImport.all_human_statuses,
|
2022-08-10 20:09:45 -04:00
|
|
|
desc: 'Return GitLab Migrations with specified status'
|
2021-07-05 08:08:33 -04:00
|
|
|
end
|
|
|
|
get do
|
|
|
|
present paginate(bulk_imports), with: Entities::BulkImport
|
|
|
|
end
|
|
|
|
|
|
|
|
desc "List all GitLab Migrations' entities" do
|
|
|
|
detail 'This feature was introduced in GitLab 14.1.'
|
2022-10-13 23:10:15 -04:00
|
|
|
success Entities::BulkImports::Entity
|
2021-07-05 08:08:33 -04:00
|
|
|
end
|
|
|
|
params do
|
|
|
|
use :pagination
|
2022-03-30 02:09:34 -04:00
|
|
|
optional :sort, type: String, values: %w[asc desc], default: 'desc',
|
2022-08-10 20:09:45 -04:00
|
|
|
desc: 'Return GitLab Migrations sorted in created by `asc` or `desc` order.'
|
2021-07-05 08:08:33 -04:00
|
|
|
optional :status, type: String, values: ::BulkImports::Entity.all_human_statuses,
|
2022-08-10 20:09:45 -04:00
|
|
|
desc: "Return all GitLab Migrations' entities with specified status"
|
2021-07-05 08:08:33 -04:00
|
|
|
end
|
|
|
|
get :entities do
|
2021-07-22 17:09:40 -04:00
|
|
|
entities = ::BulkImports::EntitiesFinder.new(
|
|
|
|
user: current_user,
|
2022-03-30 02:09:34 -04:00
|
|
|
params: params
|
2021-07-22 17:09:40 -04:00
|
|
|
).execute
|
2021-07-05 08:08:33 -04:00
|
|
|
|
|
|
|
present paginate(entities), with: Entities::BulkImports::Entity
|
|
|
|
end
|
|
|
|
|
|
|
|
desc 'Get GitLab Migration details' do
|
|
|
|
detail 'This feature was introduced in GitLab 14.1.'
|
2022-10-13 23:10:15 -04:00
|
|
|
success Entities::BulkImport
|
2021-07-05 08:08:33 -04:00
|
|
|
end
|
|
|
|
params do
|
|
|
|
requires :import_id, type: Integer, desc: "The ID of user's GitLab Migration"
|
|
|
|
end
|
|
|
|
get ':import_id' do
|
|
|
|
present bulk_import, with: Entities::BulkImport
|
|
|
|
end
|
|
|
|
|
|
|
|
desc "List GitLab Migration entities" do
|
|
|
|
detail 'This feature was introduced in GitLab 14.1.'
|
2022-10-13 23:10:15 -04:00
|
|
|
success Entities::BulkImports::Entity
|
2021-07-05 08:08:33 -04:00
|
|
|
end
|
|
|
|
params do
|
|
|
|
requires :import_id, type: Integer, desc: "The ID of user's GitLab Migration"
|
|
|
|
optional :status, type: String, values: ::BulkImports::Entity.all_human_statuses,
|
2022-08-10 20:09:45 -04:00
|
|
|
desc: 'Return import entities with specified status'
|
2021-07-05 08:08:33 -04:00
|
|
|
use :pagination
|
|
|
|
end
|
|
|
|
get ':import_id/entities' do
|
|
|
|
present paginate(bulk_import_entities), with: Entities::BulkImports::Entity
|
|
|
|
end
|
|
|
|
|
|
|
|
desc 'Get GitLab Migration entity details' do
|
|
|
|
detail 'This feature was introduced in GitLab 14.1.'
|
2022-10-13 23:10:15 -04:00
|
|
|
success Entities::BulkImports::Entity
|
2021-07-05 08:08:33 -04:00
|
|
|
end
|
|
|
|
params do
|
|
|
|
requires :import_id, type: Integer, desc: "The ID of user's GitLab Migration"
|
|
|
|
requires :entity_id, type: Integer, desc: "The ID of GitLab Migration entity"
|
|
|
|
end
|
|
|
|
get ':import_id/entities/:entity_id' do
|
|
|
|
present bulk_import_entity, with: Entities::BulkImports::Entity
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|