diff --git a/app/controllers/projects/imports_controller.rb b/app/controllers/projects/imports_controller.rb new file mode 100644 index 00000000000..b8350642804 --- /dev/null +++ b/app/controllers/projects/imports_controller.rb @@ -0,0 +1,49 @@ +class Projects::ImportsController < Projects::ApplicationController + # Authorize + before_filter :authorize_admin_project! + before_filter :require_no_repo + before_filter :redirect_if_progress, except: :show + + 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 + @project.import_start + end + end + + redirect_to project_import_path(@project) + end + + def show + unless @project.import_in_progress? + if @project.import_finished? + redirect_to(@project) and return + else + redirect_to new_project_import_path(@project) and return + end + end + end + + private + + def require_no_repo + if @project.repository_exists? + redirect_to(@project) and return + end + end + + def redirect_if_progress + if @project.import_in_progress? + redirect_to project_import_path(@project) and return + end + end +end diff --git a/app/controllers/projects/repositories_controller.rb b/app/controllers/projects/repositories_controller.rb index bcd14a1c847..3a90c1c806d 100644 --- a/app/controllers/projects/repositories_controller.rb +++ b/app/controllers/projects/repositories_controller.rb @@ -1,7 +1,14 @@ class Projects::RepositoriesController < Projects::ApplicationController # Authorize before_filter :authorize_download_code! - before_filter :require_non_empty_project + before_filter :require_non_empty_project, except: :create + before_filter :authorize_admin_project!, only: :create + + def create + @project.create_repository + + redirect_to @project + end def archive unless can?(current_user, :download_code, @project) diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index ead0127b515..fbd9e5f2a5b 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -4,7 +4,7 @@ class ProjectsController < ApplicationController before_filter :repository, except: [:new, :create] # Authorize - before_filter :authorize_admin_project!, only: [:edit, :update, :destroy, :transfer, :archive, :unarchive, :retry_import] + before_filter :authorize_admin_project!, only: [:edit, :update, :destroy, :transfer, :archive, :unarchive] layout 'navless', only: [:new, :create, :fork] before_filter :set_title, only: [:new, :create] @@ -48,7 +48,7 @@ class ProjectsController < ApplicationController def show if @project.import_in_progress? - redirect_to import_project_path(@project) + redirect_to project_import_path(@project) return end @@ -61,39 +61,22 @@ class ProjectsController < ApplicationController respond_to do |format| format.html do - if @project.empty_repo? - render "projects/empty", layout: user_layout + if @project.repository_exists? + if @project.empty_repo? + render "projects/empty", layout: user_layout + else + @last_push = current_user.recent_push(@project.id) if current_user + render :show, layout: user_layout + end else - @last_push = current_user.recent_push(@project.id) if current_user - render :show, layout: user_layout + render "projects/no_repo", layout: user_layout end end + format.json { pager_json("events/_events", @events.count) } end end - def import - if @project.import_finished? - redirect_to @project - return - end - end - - def retry_import - unless @project.import_failed? - redirect_to import_project_path(@project) - end - - @project.import_url = project_params[:import_url] - - if @project.save - @project.reload - @project.import_retry - end - - redirect_to import_project_path(@project) - end - def destroy return access_denied! unless can?(current_user, :remove_project, @project) diff --git a/app/models/project.rb b/app/models/project.rb index d7570684ac8..daf4bdd0aad 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -136,7 +136,7 @@ class Project < ActiveRecord::Base state_machine :import_status, initial: :none do event :import_start do - transition :none => :started + transition [:none, :finished] => :started end event :import_finish do diff --git a/app/views/projects/import.html.haml b/app/views/projects/import.html.haml deleted file mode 100644 index 4513c89e784..00000000000 --- a/app/views/projects/import.html.haml +++ /dev/null @@ -1,31 +0,0 @@ -- if @project.import_in_progress? - .save-project-loader - .center - %h2 - %i.fa.fa-spinner.fa-spin - Import in progress. - %p.monospace git clone --bare #{hidden_pass_url(@project.import_url)} - %p Please wait while we import the repository for you. Refresh at will. - :javascript - new ProjectImport(); - -- elsif @project.import_failed? - .save-project-loader - .center - %h2 - Import failed. Retry? - %hr - - if can?(current_user, :admin_project, @project) - = form_for @project, url: retry_import_project_path(@project), method: :put, html: { class: 'form-horizontal' } do |f| - .form-group.import-url-data - = f.label :import_url, class: 'control-label' do - %span Import existing git repo - .col-sm-10 - = f.text_field :import_url, class: 'form-control', placeholder: 'https://github.com/randx/six.git' - .bs-callout.bs-callout-info - This URL must be publicly accessible or you can add a username and password like this: https://username:password@gitlab.com/company/project.git. - %br - The import will time out after 4 minutes. For big repositories, use a clone/push combination. - For SVN repositories, check #{link_to "this migrating from SVN doc.", "http://doc.gitlab.com/ce/workflow/migrating_from_svn.html"} - .form-actions - = f.submit 'Retry import', class: "btn btn-create", tabindex: 4 diff --git a/app/views/projects/imports/new.html.haml b/app/views/projects/imports/new.html.haml new file mode 100644 index 00000000000..6c3083e49f5 --- /dev/null +++ b/app/views/projects/imports/new.html.haml @@ -0,0 +1,21 @@ +%h3.page-title + - if @project.import_failed? + Import failed. Retry? + - else + Import repository + +%hr + += form_for @project, url: project_import_path(@project), method: :post, html: { class: 'form-horizontal' } do |f| + .form-group.import-url-data + = f.label :import_url, class: 'control-label' do + %span Import existing git repo + .col-sm-10 + = f.text_field :import_url, class: 'form-control', placeholder: 'https://github.com/randx/six.git' + .bs-callout.bs-callout-info + This URL must be publicly accessible or you can add a username and password like this: https://username:password@gitlab.com/company/project.git. + %br + The import will time out after 4 minutes. For big repositories, use a clone/push combination. + For SVN repositories, check #{link_to "this migrating from SVN doc.", "http://doc.gitlab.com/ce/workflow/migrating_from_svn.html"} + .form-actions + = f.submit 'Start import', class: "btn btn-create", tabindex: 4 diff --git a/app/views/projects/imports/show.html.haml b/app/views/projects/imports/show.html.haml new file mode 100644 index 00000000000..2d1fdafed24 --- /dev/null +++ b/app/views/projects/imports/show.html.haml @@ -0,0 +1,9 @@ +.save-project-loader + .center + %h2 + %i.fa.fa-spinner.fa-spin + Import in progress. + %p.monospace git clone --bare #{hidden_pass_url(@project.import_url)} + %p Please wait while we import the repository for you. Refresh at will. + :javascript + new ProjectImport(); diff --git a/config/routes.rb b/config/routes.rb index 470fe7f4dc1..723104daf13 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -186,8 +186,6 @@ Gitlab::Application.routes.draw do post :upload_image post :toggle_star get :autocomplete_sources - get :import - put :retry_import end scope module: :projects do @@ -232,8 +230,9 @@ Gitlab::Application.routes.draw do end resource :fork, only: [:new, :create] + resource :import, only: [:new, :create, :show] - resource :repository, only: [:show] do + resource :repository, only: [:show, :create] do member do get "archive", constraints: { format: Gitlab::Regex.archive_formats_regex } end