Commit 4bde5934 authored by James Lopez's avatar James Lopez

lots of refactoring again based on feedback. Changed the UI slightly and also fixed a small bug

parent f6896f93
...@@ -3,6 +3,7 @@ class Import::GitlabProjectsController < Import::BaseController ...@@ -3,6 +3,7 @@ class Import::GitlabProjectsController < Import::BaseController
def new def new
@namespace_id = project_params[:namespace_id] @namespace_id = project_params[:namespace_id]
@namespace_name = Namespace.find(project_params[:namespace_id]).name
@path = project_params[:path] @path = project_params[:path]
end end
...@@ -23,8 +24,8 @@ class Import::GitlabProjectsController < Import::BaseController ...@@ -23,8 +24,8 @@ class Import::GitlabProjectsController < Import::BaseController
) )
else else
redirect_to( redirect_to(
new_project_path, new_import_gitlab_project_path,
alert: "Project could not be exported: #{@project.errors.full_messages.join(', ')}" alert: "Project could not be imported: #{@project.errors.full_messages.join(', ')}"
) )
end end
end end
...@@ -32,7 +33,7 @@ class Import::GitlabProjectsController < Import::BaseController ...@@ -32,7 +33,7 @@ class Import::GitlabProjectsController < Import::BaseController
private private
def file_is_valid? def file_is_valid?
project_params[:file].respond_to?(:read) project_params[:file] && project_params[:file].respond_to?(:read)
end end
def verify_gitlab_project_import_enabled def verify_gitlab_project_import_enabled
......
...@@ -7,7 +7,7 @@ class ProjectsController < Projects::ApplicationController ...@@ -7,7 +7,7 @@ class ProjectsController < Projects::ApplicationController
before_action :assign_ref_vars, :tree, only: [:show], if: :repo_exists? before_action :assign_ref_vars, :tree, only: [:show], if: :repo_exists?
# Authorize # Authorize
before_action :authorize_admin_project!, only: [:edit, :update, :housekeeping, :download_export, :export] before_action :authorize_admin_project!, only: [:edit, :update, :housekeeping, :download_export, :export, :remove_export]
before_action :event_filter, only: [:show, :activity] before_action :event_filter, only: [:show, :activity]
layout :determine_layout layout :determine_layout
...@@ -186,19 +186,38 @@ class ProjectsController < Projects::ApplicationController ...@@ -186,19 +186,38 @@ class ProjectsController < Projects::ApplicationController
end end
def export def export
@project.add_export_job(current_user_id: current_user.id) @project.add_export_job(current_user: current_user)
redirect_to( redirect_to(
edit_project_path(@project), edit_project_path(@project),
notice: "Project export started." notice: "Project export started. A download link will be sent by e-mail."
) )
end end
def download_export def download_export
export_project_path = @project.export_project_path
if export_project_path if export_project_path
send_file export_project_path, disposition: 'attachment' send_file export_project_path, disposition: 'attachment'
else else
render_404 redirect_to(
edit_project_path(@project),
alert: "Project export link has expired. Please generate a new export from your project settings."
)
end
end
def remove_export
if @project.remove_exports
redirect_to(
edit_project_path(@project),
notice: "Project export has been deleted."
)
else
redirect_to(
edit_project_path(@project),
alert: "Project export could not be deleted."
)
end end
end end
...@@ -264,8 +283,4 @@ class ProjectsController < Projects::ApplicationController ...@@ -264,8 +283,4 @@ class ProjectsController < Projects::ApplicationController
def get_id def get_id
project.repository.root_ref project.repository.root_ref
end end
def export_project_path
Dir.glob("#{@project.export_path}/*export.tar.gz").max_by {|f| File.ctime(f)}
end
end end
...@@ -348,10 +348,4 @@ module ProjectsHelper ...@@ -348,10 +348,4 @@ module ProjectsHelper
message.strip.gsub(Gitlab.config.gitlab_shell.repos_path.chomp('/'), "[REPOS PATH]") message.strip.gsub(Gitlab.config.gitlab_shell.repos_path.chomp('/'), "[REPOS PATH]")
end end
def db_export_list
YAML.load_file(Gitlab::ImportExport.config_file)['project_tree'].map do |relation|
relation.is_a?(Hash) ? relation.keys.first.to_s : relation.to_s
end + ['notes', 'merge_request_diffs']
end
end end
...@@ -1100,8 +1100,8 @@ class Project < ActiveRecord::Base ...@@ -1100,8 +1100,8 @@ class Project < ActiveRecord::Base
@errors = original_errors @errors = original_errors
end end
def add_export_job(current_user_id:) def add_export_job(current_user:)
job_id = ProjectExportWorker.perform_async(current_user_id, self.id) job_id = ProjectExportWorker.perform_async(current_user.id, self.id)
if job_id if job_id
Rails.logger.info "Export job started for project ID #{self.id} with job ID #{job_id}" Rails.logger.info "Export job started for project ID #{self.id} with job ID #{job_id}"
...@@ -1113,4 +1113,13 @@ class Project < ActiveRecord::Base ...@@ -1113,4 +1113,13 @@ class Project < ActiveRecord::Base
def export_path def export_path
File.join(Gitlab::ImportExport.storage_path, path_with_namespace) File.join(Gitlab::ImportExport.storage_path, path_with_namespace)
end end
def export_project_path
Dir.glob("#{export_path}/*export.tar.gz").max_by { |f| File.ctime(f) }
end
def remove_exports
_, status = Gitlab::Popen.popen(%W(find #{export_path} -not -path #{export_path} -delete))
status.zero?
end
end end
...@@ -54,7 +54,7 @@ module Projects ...@@ -54,7 +54,7 @@ module Projects
@project.import_start if @project.import? @project.import_start if @project.import?
after_create_actions if @project.persisted? && !@project.gitlab_project_import? after_create_actions if @project.persisted?
if @project.errors.empty? if @project.errors.empty?
@project.add_import_job if @project.import? @project.add_import_job if @project.import?
...@@ -80,16 +80,18 @@ module Projects ...@@ -80,16 +80,18 @@ module Projects
def after_create_actions def after_create_actions
log_info("#{@project.owner.name} created a new project \"#{@project.name_with_namespace}\"") log_info("#{@project.owner.name} created a new project \"#{@project.name_with_namespace}\"")
@project.create_wiki if @project.wiki_enabled? unless @project.gitlab_project_import?
@project.create_wiki if @project.wiki_enabled?
@project.build_missing_services @project.build_missing_services
@project.create_labels @project.create_labels
end
event_service.create_project(@project, current_user) event_service.create_project(@project, current_user)
system_hook_service.execute_hooks_for(@project, :create) system_hook_service.execute_hooks_for(@project, :create)
unless @project.group unless @project.group || @project.gitlab_project_import?
@project.team << [current_user, :master, current_user] @project.team << [current_user, :master, current_user]
end end
end end
......
...@@ -2,19 +2,17 @@ ...@@ -2,19 +2,17 @@
- header_title "Projects", root_path - header_title "Projects", root_path
%h3.page-title %h3.page-title
= icon('gitlab') = icon('gitlab')
Import projects from GitLab Import an exported GitLab project
%hr %hr
= form_tag import_gitlab_project_path, class: 'form-horizontal', multipart: true do = form_tag import_gitlab_project_path, class: 'form-horizontal', multipart: true do
%p %p
Project will be imported to path Project will be imported as
%strong %strong
#{@path} #{@namespace_name}/#{@path}
%p %p
To get started add your exported project file below, then you will be redirected to the new project page and the project will appear once the import is done. To move or copy an entire GitLab project from another GitLab installation to this one, navigate to the original project's settings page, generate an export file, and upload it here.
%p
You can generate a new export file from your project settings.
.form-group .form-group
= hidden_field_tag :namespace_id, @namespace_id = hidden_field_tag :namespace_id, @namespace_id
= hidden_field_tag :path, @path = hidden_field_tag :path, @path
...@@ -24,4 +22,4 @@ ...@@ -24,4 +22,4 @@
= file_field_tag :file, class: '' = file_field_tag :file, class: ''
.form-actions .form-actions
= submit_tag 'Continue to the next step', class: 'btn btn-create' = submit_tag 'Import project', class: 'btn btn-create'
...@@ -3,5 +3,7 @@ ...@@ -3,5 +3,7 @@
%p %p
The errors we encountered were: The errors we encountered were:
%h3{style: "background: black; color: red;"} %ul
#{@errors} - @errors.each do |error|
%li
error
...@@ -2,4 +2,5 @@ Project <%= @project.name %> couldn't be exported. ...@@ -2,4 +2,5 @@ Project <%= @project.name %> couldn't be exported.
The errors we encountered were: The errors we encountered were:
<%= @errors %> - @errors.each do |error|
<%= error %>
\ No newline at end of file
...@@ -126,30 +126,35 @@ ...@@ -126,30 +126,35 @@
Export project Export project
%p.append-bottom-0 %p.append-bottom-0
%p %p
Generates a compressed export file of the project and sends a link to download the export. Export this project with all its related data in order to move your project to a new GitLab instance. Once the export is finished, you can import the file from the "New Project" page.
%p
Once the exported file is ready, you will receive a notification email with a download link.
.col-lg-9 .col-lg-9
= link_to 'Export project', export_namespace_project_path(@project.namespace, @project), - if @project.export_project_path
= link_to 'Download export', download_export_namespace_project_path(@project.namespace, @project),
method: :get, class: "btn btn-default"
= link_to 'Delete export', remove_export_namespace_project_path(@project.namespace, @project),
method: :post, class: "btn btn-default"
- else
= link_to 'Export project', export_namespace_project_path(@project.namespace, @project),
method: :post, class: "btn btn-default" method: :post, class: "btn btn-default"
%p.append-bottom-0
%p
.row.prepend-top-default
Clicking on Export project, will produce a compressed file that will be sent as a link to your registered e-mail address.
.bs-callout.bs-callout-info .bs-callout.bs-callout-info
%p.append-bottom-0 %p.append-bottom-0
%p %p
The following items will be exported: The following items will be exported:
%ul %ul
%li Project and wiki repository %li Project and wiki repositories
%li Project uploads %li Project uploads
%li DB items, including configuration %li Project configuration including web hooks and services
%ul %li Issues with comments, merge requests with diffs and comments, labels, milestones, snippets, and other project entities
- db_export_list.each do |export_relation| %p
%li The following items will NOT be exported:
%code #{export_relation} %ul
%li Build traces and artifacts
%li LFS objects
%hr %hr
- if can? current_user, :archive_project, @project - if can? current_user, :archive_project, @project
.row.prepend-top-default .row.prepend-top-default
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
Forking in progress. Forking in progress.
- else - else
Import in progress. Import in progress.
- unless @project.forked? || @project.gitlab_project_import? - if @project.external_import?
%p.monospace git clone --bare #{@project.safe_import_url} %p.monospace git clone --bare #{@project.safe_import_url}
%p Please wait while we import the repository for you. Refresh at will. %p Please wait while we import the repository for you. Refresh at will.
:javascript :javascript
......
...@@ -93,7 +93,7 @@ ...@@ -93,7 +93,7 @@
- if gitlab_project_import_enabled? - if gitlab_project_import_enabled?
= link_to new_import_gitlab_project_path, class: 'btn import_gitlab_project project-submit' do = link_to new_import_gitlab_project_path, class: 'btn import_gitlab_project project-submit' do
%i.fa.fa-gitlab %i.fa.fa-gitlab
%span GitLab project %span GitLab export
.js-toggle-content.hide .js-toggle-content.hide
= render "shared/import_form", f: f = render "shared/import_form", f: f
...@@ -124,21 +124,33 @@ ...@@ -124,21 +124,33 @@
e.preventDefault(); e.preventDefault();
var import_modal = $(this).next(".modal").show(); var import_modal = $(this).next(".modal").show();
}); });
$('.modal-header .close').bind('click', function() { $('.modal-header .close').bind('click', function() {
$(".modal").hide(); $(".modal").hide();
}); });
$('.import_gitlab_project').bind('click', function() { $('.import_gitlab_project').bind('click', function() {
var _href = $("a.import_gitlab_project").attr("href"); var _href = $("a.import_gitlab_project").attr("href");
$(".import_gitlab_project").attr("href", _href + '?namespace_id=' + $("#project_namespace_id").val() + '&path=' + $("#project_path").val()); $(".import_gitlab_project").attr("href", _href + '?namespace_id=' + $("#project_namespace_id").val() + '&path=' + $("#project_path").val());
}); });
$('.import_gitlab_project').attr('disabled',true) $('.import_gitlab_project').attr('disabled',true)
$('.import_gitlab_project').attr('title', 'Project path required.'); $('.import_gitlab_project').attr('title', 'Project path required.');
$('#project_path').keyup(function(){
if($(this).val().length !=0) { $('.import_gitlab_project').click(function( event ) {
$('.import_gitlab_project').attr('disabled', false); if($('.import_gitlab_project').attr('disabled')) {
$('.import_gitlab_project').attr('title',''); event.preventDefault();
} else { new Flash("Project path required.", "alert");
$('.import_gitlab_project').attr('disabled',true); }
$('.import_gitlab_project').attr('title', 'Project path required.'); });
}
}) $('#project_path').keyup(function(){
if($(this).val().length !=0) {
$('.import_gitlab_project').attr('disabled', false);
$('.import_gitlab_project').attr('title','');
$(".flash-container").html("")
} else {
$('.import_gitlab_project').attr('disabled',true);
$('.import_gitlab_project').attr('title', 'Project path required.');
}
})
...@@ -455,6 +455,7 @@ Rails.application.routes.draw do ...@@ -455,6 +455,7 @@ Rails.application.routes.draw do
post :toggle_star post :toggle_star
post :markdown_preview post :markdown_preview
post :export post :export
post :remove_export
get :download_export get :download_export
get :autocomplete_sources get :autocomplete_sources
get :activity get :activity
......
...@@ -15,7 +15,7 @@ module Gitlab ...@@ -15,7 +15,7 @@ module Gitlab
if check_version! && [project_tree, repo_restorer, wiki_restorer, uploads_restorer].all?(&:restore) if check_version! && [project_tree, repo_restorer, wiki_restorer, uploads_restorer].all?(&:restore)
project_tree.restored_project project_tree.restored_project
else else
raise Projects::ImportService::Error.new, @shared.errors.join(', ') raise Projects::ImportService::Error.new(@shared.errors.join(', '))
end end
end end
......
...@@ -11,7 +11,8 @@ module Gitlab ...@@ -11,7 +11,8 @@ module Gitlab
end end
def restore def restore
return false unless File.exist?(@path_to_bundle) || wiki? return true if wiki?
return false unless File.exist?(@path_to_bundle)
FileUtils.mkdir_p(path_to_repo) FileUtils.mkdir_p(path_to_repo)
......
...@@ -21,7 +21,7 @@ module Gitlab ...@@ -21,7 +21,7 @@ module Gitlab
'Google Code' => 'google_code', 'Google Code' => 'google_code',
'FogBugz' => 'fogbugz', 'FogBugz' => 'fogbugz',
'Repo by URL' => 'git', 'Repo by URL' => 'git',
'GitLab project' => 'gitlab_project' 'GitLab export' => 'gitlab_export'
} }
end end
......
...@@ -25,14 +25,14 @@ feature 'project import', feature: true, js: true do ...@@ -25,14 +25,14 @@ feature 'project import', feature: true, js: true do
select2('2', from: '#project_namespace_id') select2('2', from: '#project_namespace_id')
fill_in :project_path, with:'test-project-path', visible: true fill_in :project_path, with:'test-project-path', visible: true
click_link 'GitLab project' click_link 'GitLab export'
expect(page).to have_content('GitLab project export') expect(page).to have_content('GitLab project export')
expect(URI.parse(current_url).query).to eq('namespace_id=2&path=test-project-path') expect(URI.parse(current_url).query).to eq('namespace_id=2&path=test-project-path')
attach_file('file', file) attach_file('file', file)
click_on 'Continue to the next step' # import starts click_on 'Import project' # import starts
expect(project).not_to be_nil expect(project).not_to be_nil
expect(project.issues).not_to be_empty expect(project.issues).not_to be_empty
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment