Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'app/services/import')
-rw-r--r--app/services/import/github/gists_import_service.rb10
-rw-r--r--app/services/import/github_service.rb14
2 files changed, 18 insertions, 6 deletions
diff --git a/app/services/import/github/gists_import_service.rb b/app/services/import/github/gists_import_service.rb
index df1bbe306e7..e57430916fa 100644
--- a/app/services/import/github/gists_import_service.rb
+++ b/app/services/import/github/gists_import_service.rb
@@ -3,16 +3,20 @@
module Import
module Github
class GistsImportService < ::BaseService
- def initialize(user, params)
+ def initialize(user, client, params)
@current_user = user
@params = params
+ @client = client
end
def execute
return error('Import already in progress', 422) if import_status.started?
+ check_user_token
start_import
success
+ rescue Octokit::Unauthorized
+ error('Access denied to the GitHub account.', 401)
end
private
@@ -29,6 +33,10 @@ module Import
Gitlab::GithubGistsImport::StartImportWorker.perform_async(current_user.id, encrypted_token)
import_status.start!
end
+
+ def check_user_token
+ @client.octokit.user.present?
+ end
end
end
end
diff --git a/app/services/import/github_service.rb b/app/services/import/github_service.rb
index 2378a4b11b1..b30c344723d 100644
--- a/app/services/import/github_service.rb
+++ b/app/services/import/github_service.rb
@@ -46,12 +46,8 @@ module Import
@project_name ||= params[:new_name].presence || repo[:name]
end
- def namespace_path
- @namespace_path ||= params[:target_namespace].presence || current_user.namespace_path
- end
-
def target_namespace
- @target_namespace ||= find_or_create_namespace(namespace_path, current_user.namespace_path)
+ @target_namespace ||= Namespace.find_by_full_path(target_namespace_path)
end
def extra_project_attrs
@@ -104,6 +100,8 @@ module Import
def validate_context
if blocked_url?
log_and_return_error("Invalid URL: #{url}", _("Invalid URL: %{url}") % { url: url }, :bad_request)
+ elsif target_namespace.nil?
+ error(_('Namespace or group to import repository into does not exist.'), :unprocessable_entity)
elsif !authorized?
error(_('This namespace has already been taken. Choose a different one.'), :unprocessable_entity)
elsif oversized?
@@ -111,6 +109,12 @@ module Import
end
end
+ def target_namespace_path
+ raise ArgumentError, 'Target namespace is required' if params[:target_namespace].blank?
+
+ params[:target_namespace]
+ end
+
def log_error(exception)
Gitlab::GithubImport::Logger.error(
message: 'Import failed due to a GitHub error',