2014-11-29 17:50:25 -05:00
|
|
|
class Projects::ImportsController < Projects::ApplicationController
|
2016-03-07 04:36:16 -05:00
|
|
|
include ContinueParams
|
2016-03-07 04:06:54 -05:00
|
|
|
|
2014-11-29 17:50:25 -05:00
|
|
|
# Authorize
|
2015-04-16 08:03:37 -04:00
|
|
|
before_action :authorize_admin_project!
|
2016-01-25 18:00:23 -05:00
|
|
|
before_action :require_no_repo, only: [:new, :create]
|
|
|
|
before_action :redirect_if_progress, only: [:new, :create]
|
2016-02-17 09:05:44 -05:00
|
|
|
before_action :redirect_if_no_import, only: :show
|
2014-11-29 17:50:25 -05:00
|
|
|
|
|
|
|
def new
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
|
|
|
@project.import_url = params[:project][:import_url]
|
|
|
|
|
|
|
|
if @project.save
|
|
|
|
@project.reload
|
|
|
|
|
|
|
|
if @project.import_failed?
|
|
|
|
@project.import_retry
|
|
|
|
else
|
2016-05-13 07:12:21 -04:00
|
|
|
@project.import_start
|
2016-05-12 12:27:20 -04:00
|
|
|
@project.add_import_job
|
2014-11-29 17:50:25 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-01-24 13:02:58 -05:00
|
|
|
redirect_to namespace_project_import_path(@project.namespace, @project)
|
2014-11-29 17:50:25 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def show
|
2016-01-25 18:00:23 -05:00
|
|
|
if @project.import_finished?
|
2015-12-18 04:03:34 -05:00
|
|
|
if continue_params
|
|
|
|
redirect_to continue_params[:to], notice: continue_params[:notice]
|
2014-11-29 17:50:25 -05:00
|
|
|
else
|
2016-01-25 18:00:23 -05:00
|
|
|
redirect_to namespace_project_path(@project.namespace, @project), notice: finished_notice
|
2014-11-29 17:50:25 -05:00
|
|
|
end
|
2015-12-18 04:03:34 -05:00
|
|
|
elsif @project.import_failed?
|
|
|
|
redirect_to new_namespace_project_import_path(@project.namespace, @project)
|
|
|
|
else
|
|
|
|
if continue_params && continue_params[:notice_now]
|
|
|
|
flash.now[:notice] = continue_params[:notice_now]
|
|
|
|
end
|
2016-01-25 18:00:23 -05:00
|
|
|
|
2015-12-18 04:03:34 -05:00
|
|
|
# Render
|
2014-11-29 17:50:25 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2016-01-25 18:00:23 -05:00
|
|
|
def finished_notice
|
|
|
|
if @project.forked?
|
|
|
|
'The project was successfully forked.'
|
|
|
|
else
|
|
|
|
'The project was successfully imported.'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-11-29 17:50:25 -05:00
|
|
|
def require_no_repo
|
2016-01-25 18:00:23 -05:00
|
|
|
if @project.repository_exists?
|
2016-02-17 09:05:44 -05:00
|
|
|
redirect_to namespace_project_path(@project.namespace, @project)
|
2014-11-29 17:50:25 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def redirect_if_progress
|
|
|
|
if @project.import_in_progress?
|
2016-02-17 09:05:44 -05:00
|
|
|
redirect_to namespace_project_import_path(@project.namespace, @project)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def redirect_if_no_import
|
|
|
|
if @project.repository_exists? && @project.no_import?
|
|
|
|
redirect_to namespace_project_path(@project.namespace, @project)
|
2014-11-29 17:50:25 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|