Commit 37db76a31b8d9676aeadcaf6e2e175ead0f68d74
1 parent
1436433c
Exists in
spb-stable
and in
3 other branches
Project import and retry import scaffold
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Showing
4 changed files
with
89 additions
and
55 deletions
Show diff stats
app/controllers/projects_controller.rb
| @@ -5,7 +5,7 @@ class ProjectsController < ApplicationController | @@ -5,7 +5,7 @@ class ProjectsController < ApplicationController | ||
| 5 | 5 | ||
| 6 | # Authorize | 6 | # Authorize |
| 7 | before_filter :authorize_read_project!, except: [:index, :new, :create] | 7 | before_filter :authorize_read_project!, except: [:index, :new, :create] |
| 8 | - before_filter :authorize_admin_project!, only: [:edit, :update, :destroy, :transfer, :archive, :unarchive] | 8 | + before_filter :authorize_admin_project!, only: [:edit, :update, :destroy, :transfer, :archive, :unarchive, :retry_import] |
| 9 | before_filter :require_non_empty_project, only: [:blob, :tree, :graph] | 9 | before_filter :require_non_empty_project, only: [:blob, :tree, :graph] |
| 10 | 10 | ||
| 11 | layout 'navless', only: [:new, :create, :fork] | 11 | layout 'navless', only: [:new, :create, :fork] |
| @@ -21,16 +21,9 @@ class ProjectsController < ApplicationController | @@ -21,16 +21,9 @@ class ProjectsController < ApplicationController | ||
| 21 | 21 | ||
| 22 | def create | 22 | def create |
| 23 | @project = ::Projects::CreateService.new(current_user, params[:project]).execute | 23 | @project = ::Projects::CreateService.new(current_user, params[:project]).execute |
| 24 | + flash[:notice] = 'Project was successfully created.' if @project.saved? | ||
| 24 | 25 | ||
| 25 | respond_to do |format| | 26 | respond_to do |format| |
| 26 | - flash[:notice] = 'Project was successfully created.' if @project.saved? | ||
| 27 | - format.html do | ||
| 28 | - if @project.saved? | ||
| 29 | - redirect_to @project | ||
| 30 | - else | ||
| 31 | - render "new" | ||
| 32 | - end | ||
| 33 | - end | ||
| 34 | format.js | 27 | format.js |
| 35 | end | 28 | end |
| 36 | end | 29 | end |
| @@ -67,9 +60,7 @@ class ProjectsController < ApplicationController | @@ -67,9 +60,7 @@ class ProjectsController < ApplicationController | ||
| 67 | if @project.empty_repo? | 60 | if @project.empty_repo? |
| 68 | render "projects/empty", layout: user_layout | 61 | render "projects/empty", layout: user_layout |
| 69 | else | 62 | else |
| 70 | - if current_user | ||
| 71 | - @last_push = current_user.recent_push(@project.id) | ||
| 72 | - end | 63 | + @last_push = current_user.recent_push(@project.id) if current_user |
| 73 | render :show, layout: user_layout | 64 | render :show, layout: user_layout |
| 74 | end | 65 | end |
| 75 | end | 66 | end |
| @@ -77,6 +68,28 @@ class ProjectsController < ApplicationController | @@ -77,6 +68,28 @@ class ProjectsController < ApplicationController | ||
| 77 | end | 68 | end |
| 78 | end | 69 | end |
| 79 | 70 | ||
| 71 | + def import | ||
| 72 | + if project.import_finished? | ||
| 73 | + redirect_to @project | ||
| 74 | + return | ||
| 75 | + end | ||
| 76 | + end | ||
| 77 | + | ||
| 78 | + def retry_import | ||
| 79 | + unless @project.import_failed? | ||
| 80 | + redirect_to import_project_path(@project) | ||
| 81 | + end | ||
| 82 | + | ||
| 83 | + @project.import_url = params[:project][:import_url] | ||
| 84 | + | ||
| 85 | + if @project.save | ||
| 86 | + @project.reload | ||
| 87 | + @project.import_retry | ||
| 88 | + end | ||
| 89 | + | ||
| 90 | + redirect_to import_project_path(@project) | ||
| 91 | + end | ||
| 92 | + | ||
| 80 | def destroy | 93 | def destroy |
| 81 | return access_denied! unless can?(current_user, :remove_project, project) | 94 | return access_denied! unless can?(current_user, :remove_project, project) |
| 82 | 95 |
app/views/projects/create.js.haml
| 1 | - if @project.saved? | 1 | - if @project.saved? |
| 2 | - :plain | ||
| 3 | - location.href = "#{project_path(@project)}"; | 2 | + - if @project.import? |
| 3 | + :plain | ||
| 4 | + location.href = "#{import_project_path(@project)}"; | ||
| 5 | + - else | ||
| 6 | + :plain | ||
| 7 | + location.href = "#{project_path(@project)}"; | ||
| 4 | - else | 8 | - else |
| 5 | :plain | 9 | :plain |
| 6 | $(".project-edit-errors").html("#{escape_javascript(render('errors'))}"); | 10 | $(".project-edit-errors").html("#{escape_javascript(render('errors'))}"); |
app/views/projects/empty.html.haml
| 1 | = render "home_panel" | 1 | = render "home_panel" |
| 2 | 2 | ||
| 3 | -- if @project.import? && !@project.imported | ||
| 4 | - .save-project-loader | ||
| 5 | - %center | ||
| 6 | - %h2 | ||
| 7 | - %i.icon-spinner.icon-spin | ||
| 8 | - Importing repository. | ||
| 9 | - %p.monospace git clone --bare #{@project.import_url} | ||
| 10 | - %p Please wait while we import the repository for you. Refresh at will. | ||
| 11 | - :javascript | ||
| 12 | - new ProjectImport(); | 3 | +%div.git-empty |
| 4 | + %fieldset | ||
| 5 | + %legend Git global setup: | ||
| 6 | + %pre.dark | ||
| 7 | + :preserve | ||
| 8 | + git config --global user.name "#{git_user_name}" | ||
| 9 | + git config --global user.email "#{git_user_email}" | ||
| 13 | 10 | ||
| 14 | -- else | ||
| 15 | - %div.git-empty | ||
| 16 | - %fieldset | ||
| 17 | - %legend Git global setup: | ||
| 18 | - %pre.dark | ||
| 19 | - :preserve | ||
| 20 | - git config --global user.name "#{git_user_name}" | ||
| 21 | - git config --global user.email "#{git_user_email}" | 11 | + %fieldset |
| 12 | + %legend Create Repository | ||
| 13 | + %pre.dark | ||
| 14 | + :preserve | ||
| 15 | + mkdir #{@project.path} | ||
| 16 | + cd #{@project.path} | ||
| 17 | + git init | ||
| 18 | + touch README | ||
| 19 | + git add README | ||
| 20 | + git commit -m 'first commit' | ||
| 21 | + git remote add origin #{ content_tag(:span, default_url_to_repo, class: 'clone')} | ||
| 22 | + git push -u origin master | ||
| 22 | 23 | ||
| 23 | - %fieldset | ||
| 24 | - %legend Create Repository | ||
| 25 | - %pre.dark | ||
| 26 | - :preserve | ||
| 27 | - mkdir #{@project.path} | ||
| 28 | - cd #{@project.path} | ||
| 29 | - git init | ||
| 30 | - touch README | ||
| 31 | - git add README | ||
| 32 | - git commit -m 'first commit' | ||
| 33 | - git remote add origin #{ content_tag(:span, default_url_to_repo, class: 'clone')} | ||
| 34 | - git push -u origin master | 24 | + %fieldset |
| 25 | + %legend Existing Git Repo? | ||
| 26 | + %pre.dark | ||
| 27 | + :preserve | ||
| 28 | + cd existing_git_repo | ||
| 29 | + git remote add origin #{ content_tag(:span, default_url_to_repo, class: 'clone')} | ||
| 30 | + git push -u origin master | ||
| 35 | 31 | ||
| 36 | - %fieldset | ||
| 37 | - %legend Existing Git Repo? | ||
| 38 | - %pre.dark | ||
| 39 | - :preserve | ||
| 40 | - cd existing_git_repo | ||
| 41 | - git remote add origin #{ content_tag(:span, default_url_to_repo, class: 'clone')} | ||
| 42 | - git push -u origin master | ||
| 43 | - | ||
| 44 | - - if can? current_user, :remove_project, @project | ||
| 45 | - .prepend-top-20 | ||
| 46 | - = link_to 'Remove project', @project, data: { confirm: remove_project_message(@project)}, method: :delete, class: "btn btn-remove pull-right" | 32 | +- if can? current_user, :remove_project, @project |
| 33 | + .prepend-top-20 | ||
| 34 | + = link_to 'Remove project', @project, data: { confirm: remove_project_message(@project)}, method: :delete, class: "btn btn-remove pull-right" |
| @@ -0,0 +1,29 @@ | @@ -0,0 +1,29 @@ | ||
| 1 | +- if @project.import_in_progress? | ||
| 2 | + .save-project-loader | ||
| 3 | + %center | ||
| 4 | + %h2 | ||
| 5 | + %i.icon-spinner.icon-spin | ||
| 6 | + Import in progress. | ||
| 7 | + %p.monospace git clone --bare #{@project.import_url} | ||
| 8 | + %p Please wait while we import the repository for you. Refresh at will. | ||
| 9 | + :javascript | ||
| 10 | + new ProjectImport(); | ||
| 11 | + | ||
| 12 | +- elsif @project.import_failed? | ||
| 13 | + .save-project-loader | ||
| 14 | + %center | ||
| 15 | + %h2 | ||
| 16 | + Import failed. Retry? | ||
| 17 | + %hr | ||
| 18 | + = form_for @project, url: retry_import_project_path(@project), method: :put, html: { class: 'form-horizontal' } do |f| | ||
| 19 | + .form-group.import-url-data | ||
| 20 | + = f.label :import_url, class: 'control-label' do | ||
| 21 | + %span Import existing repo | ||
| 22 | + .col-sm-10 | ||
| 23 | + = f.text_field :import_url, class: 'form-control', placeholder: 'https://github.com/randx/six.git' | ||
| 24 | + .bs-callout.bs-callout-info | ||
| 25 | + This url must be publicly accessible or you can add a username and password like this: https://username:password@gitlab.com/company/project.git. | ||
| 26 | + %br | ||
| 27 | + The import will time out after 2 minutes. For big repositories, use a clone/push combination. | ||
| 28 | + .form-actions | ||
| 29 | + = f.submit 'Retry import', class: "btn btn-create", tabindex: 4 |