diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-06-18 14:18:50 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-06-18 14:18:50 +0300 |
commit | 8c7f4e9d5f36cff46365a7f8c4b9c21578c1e781 (patch) | |
tree | a77e7fe7a93de11213032ed4ab1f33a3db51b738 /app/controllers/import/bitbucket_controller.rb | |
parent | 00b35af3db1abfe813a778f643dad221aad51fca (diff) |
Add latest changes from gitlab-org/gitlab@13-1-stable-ee
Diffstat (limited to 'app/controllers/import/bitbucket_controller.rb')
-rw-r--r-- | app/controllers/import/bitbucket_controller.rb | 53 |
1 files changed, 47 insertions, 6 deletions
diff --git a/app/controllers/import/bitbucket_controller.rb b/app/controllers/import/bitbucket_controller.rb index c37e799de62..4886aeb5e3f 100644 --- a/app/controllers/import/bitbucket_controller.rb +++ b/app/controllers/import/bitbucket_controller.rb @@ -1,6 +1,8 @@ # frozen_string_literal: true class Import::BitbucketController < Import::BaseController + extend ::Gitlab::Utils::Override + include ActionView::Helpers::SanitizeHelper before_action :verify_bitbucket_import_enabled @@ -10,7 +12,7 @@ class Import::BitbucketController < Import::BaseController rescue_from Bitbucket::Error::Unauthorized, with: :bitbucket_unauthorized def callback - response = client.auth_code.get_token(params[:code], redirect_uri: users_import_bitbucket_callback_url) + response = oauth_client.auth_code.get_token(params[:code], redirect_uri: users_import_bitbucket_callback_url) session[:bitbucket_token] = response.token session[:bitbucket_expires_at] = response.expires_at @@ -22,9 +24,10 @@ class Import::BitbucketController < Import::BaseController # rubocop: disable CodeReuse/ActiveRecord def status + return super if Feature.enabled?(:new_import_ui) + bitbucket_client = Bitbucket::Client.new(credentials) repos = bitbucket_client.repos(filter: sanitized_filter_param) - @repos, @incompatible_repos = repos.partition { |repo| repo.valid? } @already_added_projects = find_already_added_projects('bitbucket') @@ -38,6 +41,10 @@ class Import::BitbucketController < Import::BaseController render json: find_jobs('bitbucket') end + def realtime_changes + super + end + def create bitbucket_client = Bitbucket::Client.new(credentials) @@ -59,7 +66,7 @@ class Import::BitbucketController < Import::BaseController project = Gitlab::BitbucketImport::ProjectCreator.new(repo, project_name, target_namespace, current_user, credentials).execute if project.persisted? - render json: ProjectSerializer.new.represent(project) + render json: ProjectSerializer.new.represent(project, serializer: :import) else render json: { errors: project_save_error(project) }, status: :unprocessable_entity end @@ -68,16 +75,50 @@ class Import::BitbucketController < Import::BaseController end end + protected + + # rubocop: disable CodeReuse/ActiveRecord + override :importable_repos + def importable_repos + already_added_projects_names = already_added_projects.map(&:import_source) + + bitbucket_repos.reject { |repo| already_added_projects_names.include?(repo.full_name) || !repo.valid? } + end + # rubocop: enable CodeReuse/ActiveRecord + + override :incompatible_repos + def incompatible_repos + bitbucket_repos.reject { |repo| repo.valid? } + end + + override :provider_name + def provider_name + :bitbucket + end + + override :provider_url + def provider_url + provider.url + end + private - def client - @client ||= OAuth2::Client.new(provider.app_id, provider.app_secret, options) + def oauth_client + @oauth_client ||= OAuth2::Client.new(provider.app_id, provider.app_secret, options) end def provider Gitlab::Auth::OAuth::Provider.config_for('bitbucket') end + def client + @client ||= Bitbucket::Client.new(credentials) + end + + def bitbucket_repos + @bitbucket_repos ||= client.repos(filter: sanitized_filter_param).to_a + end + def options OmniAuth::Strategies::Bitbucket.default_options[:client_options].deep_symbolize_keys end @@ -91,7 +132,7 @@ class Import::BitbucketController < Import::BaseController end def go_to_bitbucket_for_permissions - redirect_to client.auth_code.authorize_url(redirect_uri: users_import_bitbucket_callback_url) + redirect_to oauth_client.auth_code.authorize_url(redirect_uri: users_import_bitbucket_callback_url) end def bitbucket_unauthorized |