diff options
Diffstat (limited to 'app/controllers/import')
-rw-r--r-- | app/controllers/import/base_controller.rb | 8 | ||||
-rw-r--r-- | app/controllers/import/bitbucket_controller.rb | 4 | ||||
-rw-r--r-- | app/controllers/import/bitbucket_server_controller.rb | 4 | ||||
-rw-r--r-- | app/controllers/import/bulk_imports_controller.rb | 40 | ||||
-rw-r--r-- | app/controllers/import/github_controller.rb | 20 |
5 files changed, 47 insertions, 29 deletions
diff --git a/app/controllers/import/base_controller.rb b/app/controllers/import/base_controller.rb index 151ba46e629..87cda723895 100644 --- a/app/controllers/import/base_controller.rb +++ b/app/controllers/import/base_controller.rb @@ -48,18 +48,14 @@ class Import::BaseController < ApplicationController private - def filter_attribute - :name - end - def sanitized_filter_param - @filter ||= sanitize(params[:filter]) + @filter ||= sanitize(params[:filter])&.downcase end def filtered(collection) return collection unless sanitized_filter_param - collection.select { |item| item[filter_attribute].include?(sanitized_filter_param) } + collection.select { |item| item[:name].to_s.downcase.include?(sanitized_filter_param) } end def serialized_provider_repos diff --git a/app/controllers/import/bitbucket_controller.rb b/app/controllers/import/bitbucket_controller.rb index 0ffd9ef8bdd..57bd39bbe06 100644 --- a/app/controllers/import/bitbucket_controller.rb +++ b/app/controllers/import/bitbucket_controller.rb @@ -132,8 +132,4 @@ class Import::BitbucketController < Import::BaseController refresh_token: session[:bitbucket_refresh_token] } end - - def sanitized_filter_param - @filter ||= sanitize(params[:filter]) - end end diff --git a/app/controllers/import/bitbucket_server_controller.rb b/app/controllers/import/bitbucket_server_controller.rb index bee78cb3283..1846b1e0cec 100644 --- a/app/controllers/import/bitbucket_server_controller.rb +++ b/app/controllers/import/bitbucket_server_controller.rb @@ -170,10 +170,6 @@ class Import::BitbucketServerController < Import::BaseController BitbucketServer::Paginator::PAGE_LENGTH end - def sanitized_filter_param - sanitize(params[:filter]) - end - def bitbucket_connection_error(error) flash[:alert] = _("Unable to connect to server: %{error}") % { error: error } clear_session_data diff --git a/app/controllers/import/bulk_imports_controller.rb b/app/controllers/import/bulk_imports_controller.rb index cb2922c2d47..78f4a0cffca 100644 --- a/app/controllers/import/bulk_imports_controller.rb +++ b/app/controllers/import/bulk_imports_controller.rb @@ -6,13 +6,13 @@ class Import::BulkImportsController < ApplicationController feature_category :importers - rescue_from Gitlab::BulkImport::Client::ConnectionError, with: :bulk_import_connection_error + rescue_from BulkImports::Clients::Http::ConnectionError, with: :bulk_import_connection_error def configure - session[access_token_key] = params[access_token_key]&.strip - session[url_key] = params[url_key] + session[access_token_key] = configure_params[access_token_key]&.strip + session[url_key] = configure_params[url_key] - redirect_to status_import_bulk_import_url + redirect_to status_import_bulk_imports_url end def status @@ -25,6 +25,12 @@ class Import::BulkImportsController < ApplicationController end end + def create + BulkImportService.new(current_user, create_params, credentials).execute + + render json: :ok + end + private def serialized_importable_data @@ -36,20 +42,33 @@ class Import::BulkImportsController < ApplicationController end def importable_data - client.get('groups', top_level_only: true) + client.get('groups', top_level_only: true).parsed_response end def client - @client ||= Gitlab::BulkImport::Client.new( + @client ||= BulkImports::Clients::Http.new( uri: session[url_key], token: session[access_token_key] ) end - def import_params + def configure_params params.permit(access_token_key, url_key) end + def create_params + params.permit(:bulk_import, [*bulk_import_params]) + end + + def bulk_import_params + %i[ + source_type + source_full_path + destination_name + destination_namespace + ] + end + def ensure_group_import_enabled render_404 unless Feature.enabled?(:bulk_import) end @@ -106,4 +125,11 @@ class Import::BulkImportsController < ApplicationController session[url_key] = nil session[access_token_key] = nil end + + def credentials + { + url: session[url_key], + access_token: [access_token_key] + } + end end diff --git a/app/controllers/import/github_controller.rb b/app/controllers/import/github_controller.rb index a1adc6e062a..8ac93aeb9c0 100644 --- a/app/controllers/import/github_controller.rb +++ b/app/controllers/import/github_controller.rb @@ -15,6 +15,7 @@ class Import::GithubController < Import::BaseController rescue_from OAuthConfigMissingError, with: :missing_oauth_config rescue_from Octokit::Unauthorized, with: :provider_unauthorized rescue_from Octokit::TooManyRequests, with: :provider_rate_limit + rescue_from Gitlab::GithubImport::RateLimitError, with: :rate_limit_threshold_exceeded def new if !ci_cd_only? && github_import_configured? && logged_in_with_provider? @@ -114,7 +115,7 @@ class Import::GithubController < Import::BaseController def client_repos @client_repos ||= if Feature.enabled?(:remove_legacy_github_client) - filtered(concatenated_repos) + concatenated_repos else filtered(client.repos) end @@ -122,8 +123,15 @@ class Import::GithubController < Import::BaseController def concatenated_repos return [] unless client.respond_to?(:each_page) + return client.each_page(:repos).flat_map(&:objects) unless sanitized_filter_param - client.each_page(:repos).flat_map(&:objects) + client.search_repos_by_name(sanitized_filter_param).flat_map(&:objects).flat_map(&:items) + end + + def sanitized_filter_param + super + + @filter = @filter&.tr(' ', '')&.tr(':', '') end def oauth_client @@ -246,12 +254,8 @@ class Import::GithubController < Import::BaseController {} end - def sanitized_filter_param - @filter ||= sanitize(params[:filter]) - end - - def filter_attribute - :name + def rate_limit_threshold_exceeded + head :too_many_requests end end |