2020-07-28 23:09:34 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module API
|
2021-01-03 14:25:43 +05:30
|
|
|
class ImportBitbucketServer < ::API::Base
|
2021-01-29 00:20:46 +05:30
|
|
|
feature_category :importers
|
2022-07-16 23:28:13 +05:30
|
|
|
urgency :low
|
2021-09-30 23:02:18 +05:30
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
helpers do
|
|
|
|
def client
|
|
|
|
@client ||= BitbucketServer::Client.new(credentials)
|
|
|
|
end
|
|
|
|
|
|
|
|
def credentials
|
|
|
|
@credentials ||= {
|
|
|
|
base_uri: params[:bitbucket_server_url],
|
|
|
|
user: params[:bitbucket_server_username],
|
|
|
|
password: params[:personal_access_token]
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
desc 'Import a BitBucket Server repository' do
|
|
|
|
detail 'This feature was introduced in GitLab 13.2.'
|
|
|
|
success ::ProjectEntity
|
2023-01-13 00:05:48 +05:30
|
|
|
failure [
|
|
|
|
{ code: 400, message: 'Bad request' },
|
|
|
|
{ code: 401, message: 'Unauthorized' },
|
|
|
|
{ code: 403, message: 'Forbidden' },
|
|
|
|
{ code: 422, message: 'Unprocessable entity' },
|
|
|
|
{ code: 503, message: 'Service unavailable' }
|
|
|
|
]
|
|
|
|
tags ['project_import_bitbucket']
|
2020-07-28 23:09:34 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
params do
|
|
|
|
requires :bitbucket_server_url, type: String, desc: 'Bitbucket Server URL'
|
|
|
|
requires :bitbucket_server_username, type: String, desc: 'BitBucket Server Username'
|
|
|
|
requires :personal_access_token, type: String, desc: 'BitBucket Server personal access token/password'
|
|
|
|
requires :bitbucket_server_project, type: String, desc: 'BitBucket Server Project Key'
|
|
|
|
requires :bitbucket_server_repo, type: String, desc: 'BitBucket Server Repository Name'
|
|
|
|
optional :new_name, type: String, desc: 'New repo name'
|
|
|
|
optional :new_namespace, type: String, desc: 'Namespace to import repo into'
|
|
|
|
end
|
|
|
|
|
|
|
|
post 'import/bitbucket_server' do
|
|
|
|
result = Import::BitbucketServerService.new(client, current_user, params).execute(credentials)
|
|
|
|
|
|
|
|
if result[:status] == :success
|
|
|
|
present ProjectSerializer.new.represent(result[:project], serializer: :import)
|
|
|
|
else
|
|
|
|
render_api_error!({ error: result[:message] }, result[:http_status])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|