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:
-rw-r--r--app/controllers/import/gitlab_projects_controller.rb25
-rw-r--r--app/views/import/gitlab_projects/new.html.haml5
-rw-r--r--app/views/import/gitlab_projects/status.html.haml0
-rw-r--r--lib/gitlab/gitlab_import/project_creator.rb4
-rw-r--r--lib/gitlab/import_export/project_creator.rb29
5 files changed, 55 insertions, 8 deletions
diff --git a/app/controllers/import/gitlab_projects_controller.rb b/app/controllers/import/gitlab_projects_controller.rb
index a4ac55cd2a4..90b4ff8b2ca 100644
--- a/app/controllers/import/gitlab_projects_controller.rb
+++ b/app/controllers/import/gitlab_projects_controller.rb
@@ -2,24 +2,41 @@ class Import::GitlabProjectsController < Import::BaseController
before_action :verify_gitlab_project_import_enabled
before_action :verify_project_and_namespace_access
- rescue_from OAuth::Error, with: :gitlab_project_unauthorized
-
def new
@namespace_id = project_params[:namespace_id]
@path = project_params[:path]
end
def create
+ unless file_is_valid?
+ return redirect_back_or_default(options: { alert: "You need to upload a GitLab project export archive." })
+ end
+
@project = Project.create_from_import_job(current_user_id: current_user.id,
tmp_file: File.expand_path(params[:file].path),
namespace_id: project_params[:namespace_id],
project_path: project_params[:path])
- redirect_to dashboard_projects_path
+ @project = Gitlab::GitlabImport::ProjectCreator.new(repo, namespace, current_user, access_params).execute
+
+ flash[:notice] = "The project import has been started."
+
+ if @project.saved?
+ redirect_to(
+ project_path(@project),
+ notice: "Project '#{@project.name}' is being imported."
+ )
+ else
+ render 'new'
+ end
end
private
+ def file_is_valid?
+ params[:file].respond_to?(:read) && params[:file].content_type == 'application/x-gzip'
+ end
+
def verify_project_and_namespace_access
unless namespace_access?
render_403
@@ -27,7 +44,7 @@ class Import::GitlabProjectsController < Import::BaseController
end
def namespace_access?
- current_user.can?(:create_projects, Namespace.find(project_params[:namespace_id]))
+ can?(current_user, :create_projects, Namespace.find(project_params[:namespace_id]))
end
def verify_gitlab_project_import_enabled
diff --git a/app/views/import/gitlab_projects/new.html.haml b/app/views/import/gitlab_projects/new.html.haml
index d93ae42c1bf..1e7a65715b0 100644
--- a/app/views/import/gitlab_projects/new.html.haml
+++ b/app/views/import/gitlab_projects/new.html.haml
@@ -1,12 +1,15 @@
- page_title "GitLab Import"
- header_title "Projects", root_path
%h3.page-title
- %i.fa.fa-gitlab
+ = icon('gitlab')
Import projects from GitLab
%hr
= form_tag import_gitlab_project_path, class: 'form-horizontal', multipart: true do
%p
+ Project will be imported to path #{@path}
+
+ %p
To get started add your exported project file below:
.form-group
= hidden_field_tag :namespace_id, @namespace_id
diff --git a/app/views/import/gitlab_projects/status.html.haml b/app/views/import/gitlab_projects/status.html.haml
deleted file mode 100644
index e69de29bb2d..00000000000
--- a/app/views/import/gitlab_projects/status.html.haml
+++ /dev/null
diff --git a/lib/gitlab/gitlab_import/project_creator.rb b/lib/gitlab/gitlab_import/project_creator.rb
index 77c33db4b59..3d0418261bb 100644
--- a/lib/gitlab/gitlab_import/project_creator.rb
+++ b/lib/gitlab/gitlab_import/project_creator.rb
@@ -11,7 +11,7 @@ module Gitlab
end
def execute
- project = ::Projects::CreateService.new(
+ ::Projects::CreateService.new(
current_user,
name: repo["name"],
path: repo["path"],
@@ -22,8 +22,6 @@ module Gitlab
import_source: repo["path_with_namespace"],
import_url: repo["http_url_to_repo"].sub("://", "://oauth2:#{@session_data[:gitlab_access_token]}@")
).execute
-
- project
end
end
end
diff --git a/lib/gitlab/import_export/project_creator.rb b/lib/gitlab/import_export/project_creator.rb
new file mode 100644
index 00000000000..b8424cb9719
--- /dev/null
+++ b/lib/gitlab/import_export/project_creator.rb
@@ -0,0 +1,29 @@
+module Gitlab
+ module ImportExport
+ class ProjectCreator
+
+ def initialize(namespace_id, current_user, )
+ @repo = repo
+ @namespace = Namespace.find_by_id(namespace_id)
+ @current_user = current_user
+ @user_map = user_map
+ end
+
+ def execute
+ ::Projects::CreateService.new(
+ current_user,
+ name: repo.name,
+ path: repo.name,
+ description: repo.summary,
+ namespace: namespace,
+ creator: current_user,
+ visibility_level: Gitlab::VisibilityLevel::PUBLIC,
+ import_type: "google_code",
+ import_source: repo.name,
+ import_url: repo.import_url,
+ import_data: { data: { 'repo' => repo.raw_data, 'user_map' => user_map } }
+ ).execute
+ end
+ end
+ end
+end