summaryrefslogtreecommitdiff
path: root/app/controllers/import
diff options
context:
space:
mode:
authorValery Sizov <valery@gitlab.com>2015-02-05 10:31:36 -0800
committerValery Sizov <valery@gitlab.com>2015-02-05 17:03:43 -0800
commit1ac20698a5122111c8e12de4cc59da837b0f9573 (patch)
tree67442cc67cf4d7aa4f3e0c66d11d4728eb4fa8ca /app/controllers/import
parent2d5765bd2ca9b7ce3e4251cb082cbc8c52e51996 (diff)
downloadgitlab-ce-1ac20698a5122111c8e12de4cc59da837b0f9573.tar.gz
gitlab.com importer: refactorig
Diffstat (limited to 'app/controllers/import')
-rw-r--r--app/controllers/import/base_controller.rb21
-rw-r--r--app/controllers/import/github_controller.rb22
-rw-r--r--app/controllers/import/gitlab_controller.rb20
3 files changed, 30 insertions, 33 deletions
diff --git a/app/controllers/import/base_controller.rb b/app/controllers/import/base_controller.rb
new file mode 100644
index 00000000000..4df171dbcfe
--- /dev/null
+++ b/app/controllers/import/base_controller.rb
@@ -0,0 +1,21 @@
+class Import::BaseController < ApplicationController
+
+ private
+
+ def get_or_create_namespace
+ existing_namespace = Namespace.find_by("path = ? OR name = ?", @target_namespace, @target_namespace)
+
+ if existing_namespace
+ if existing_namespace.owner == current_user
+ namespace = existing_namespace
+ else
+ @already_been_taken = true
+ return false
+ end
+ else
+ namespace = Group.create(name: @target_namespace, path: @target_namespace, owner: current_user)
+ namespace.add_owner(current_user)
+ namespace
+ end
+ end
+end
diff --git a/app/controllers/import/github_controller.rb b/app/controllers/import/github_controller.rb
index 08419a37476..108fc4396a6 100644
--- a/app/controllers/import/github_controller.rb
+++ b/app/controllers/import/github_controller.rb
@@ -1,4 +1,4 @@
-class Import::GithubController < ApplicationController
+class Import::GithubController < Import::BaseController
before_filter :github_auth, except: :callback
rescue_from Octokit::Unauthorized, with: :github_unauthorized
@@ -30,22 +30,10 @@ class Import::GithubController < ApplicationController
def create
@repo_id = params[:repo_id].to_i
repo = octo_client.repo(@repo_id)
- target_namespace = params[:new_namespace].presence || repo.owner.login
- existing_namespace = Namespace.find_by("path = ? OR name = ?", target_namespace, target_namespace)
-
- if existing_namespace
- if existing_namespace.owner == current_user
- namespace = existing_namespace
- else
- @already_been_taken = true
- @target_namespace = target_namespace
- @project_name = repo.name
- render and return
- end
- else
- namespace = Group.create(name: target_namespace, path: target_namespace, owner: current_user)
- namespace.add_owner(current_user)
- end
+ @target_namespace = params[:new_namespace].presence || repo.owner.login
+ @project_name = repo.name
+
+ namespace = get_or_create_namespace || (render and return)
@project = Gitlab::GithubImport::ProjectCreator.new(repo, namespace, current_user).execute
end
diff --git a/app/controllers/import/gitlab_controller.rb b/app/controllers/import/gitlab_controller.rb
index 448fe6417be..a51ea36aff8 100644
--- a/app/controllers/import/gitlab_controller.rb
+++ b/app/controllers/import/gitlab_controller.rb
@@ -1,4 +1,4 @@
-class Import::GitlabController < ApplicationController
+class Import::GitlabController < Import::BaseController
before_filter :gitlab_auth, except: :callback
rescue_from OAuth2::Error, with: :gitlab_unauthorized
@@ -27,22 +27,10 @@ class Import::GitlabController < ApplicationController
def create
@repo_id = params[:repo_id].to_i
repo = client.project(@repo_id)
- target_namespace = params[:new_namespace].presence || repo["namespace"]["path"]
- existing_namespace = Namespace.find_by("path = ? OR name = ?", target_namespace, target_namespace)
+ @target_namespace = params[:new_namespace].presence || repo["namespace"]["path"]
+ @project_name = repo["name"]
- if existing_namespace
- if existing_namespace.owner == current_user
- namespace = existing_namespace
- else
- @already_been_taken = true
- @target_namespace = target_namespace
- @project_name = repo["path"]
- render and return
- end
- else
- namespace = Group.create(name: target_namespace, path: target_namespace, owner: current_user)
- namespace.add_owner(current_user)
- end
+ namespace = get_or_create_namespace || (render and return)
@project = Gitlab::GitlabImport::ProjectCreator.new(repo, namespace, current_user).execute
end