lots of refactoring again based on feedback. Changed the UI slightly and also fixed a small bug
This commit is contained in:
parent
f6896f9381
commit
4bde59341f
16 changed files with 105 additions and 64 deletions
|
@ -3,6 +3,7 @@ class Import::GitlabProjectsController < Import::BaseController
|
|||
|
||||
def new
|
||||
@namespace_id = project_params[:namespace_id]
|
||||
@namespace_name = Namespace.find(project_params[:namespace_id]).name
|
||||
@path = project_params[:path]
|
||||
end
|
||||
|
||||
|
@ -23,8 +24,8 @@ class Import::GitlabProjectsController < Import::BaseController
|
|||
)
|
||||
else
|
||||
redirect_to(
|
||||
new_project_path,
|
||||
alert: "Project could not be exported: #{@project.errors.full_messages.join(', ')}"
|
||||
new_import_gitlab_project_path,
|
||||
alert: "Project could not be imported: #{@project.errors.full_messages.join(', ')}"
|
||||
)
|
||||
end
|
||||
end
|
||||
|
@ -32,7 +33,7 @@ class Import::GitlabProjectsController < Import::BaseController
|
|||
private
|
||||
|
||||
def file_is_valid?
|
||||
project_params[:file].respond_to?(:read)
|
||||
project_params[:file] && project_params[:file].respond_to?(:read)
|
||||
end
|
||||
|
||||
def verify_gitlab_project_import_enabled
|
||||
|
|
|
@ -7,7 +7,7 @@ class ProjectsController < Projects::ApplicationController
|
|||
before_action :assign_ref_vars, :tree, only: [:show], if: :repo_exists?
|
||||
|
||||
# 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]
|
||||
|
||||
layout :determine_layout
|
||||
|
@ -186,19 +186,38 @@ class ProjectsController < Projects::ApplicationController
|
|||
end
|
||||
|
||||
def export
|
||||
@project.add_export_job(current_user_id: current_user.id)
|
||||
@project.add_export_job(current_user: current_user)
|
||||
|
||||
redirect_to(
|
||||
edit_project_path(@project),
|
||||
notice: "Project export started."
|
||||
notice: "Project export started. A download link will be sent by e-mail."
|
||||
)
|
||||
end
|
||||
|
||||
def download_export
|
||||
export_project_path = @project.export_project_path
|
||||
|
||||
if export_project_path
|
||||
send_file export_project_path, disposition: 'attachment'
|
||||
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
|
||||
|
||||
|
@ -264,8 +283,4 @@ class ProjectsController < Projects::ApplicationController
|
|||
def get_id
|
||||
project.repository.root_ref
|
||||
end
|
||||
|
||||
def export_project_path
|
||||
Dir.glob("#{@project.export_path}/*export.tar.gz").max_by {|f| File.ctime(f)}
|
||||
end
|
||||
end
|
||||
|
|
|
@ -348,10 +348,4 @@ module ProjectsHelper
|
|||
|
||||
message.strip.gsub(Gitlab.config.gitlab_shell.repos_path.chomp('/'), "[REPOS PATH]")
|
||||
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
|
||||
|
|
|
@ -1100,8 +1100,8 @@ class Project < ActiveRecord::Base
|
|||
@errors = original_errors
|
||||
end
|
||||
|
||||
def add_export_job(current_user_id:)
|
||||
job_id = ProjectExportWorker.perform_async(current_user_id, self.id)
|
||||
def add_export_job(current_user:)
|
||||
job_id = ProjectExportWorker.perform_async(current_user.id, self.id)
|
||||
|
||||
if 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
|
|||
def export_path
|
||||
File.join(Gitlab::ImportExport.storage_path, path_with_namespace)
|
||||
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
|
||||
|
|
|
@ -54,7 +54,7 @@ module Projects
|
|||
|
||||
@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?
|
||||
@project.add_import_job if @project.import?
|
||||
|
@ -80,16 +80,18 @@ module Projects
|
|||
def after_create_actions
|
||||
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)
|
||||
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]
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,19 +2,17 @@
|
|||
- header_title "Projects", root_path
|
||||
%h3.page-title
|
||||
= icon('gitlab')
|
||||
Import projects from GitLab
|
||||
Import an exported GitLab project
|
||||
%hr
|
||||
|
||||
= form_tag import_gitlab_project_path, class: 'form-horizontal', multipart: true do
|
||||
%p
|
||||
Project will be imported to path
|
||||
Project will be imported as
|
||||
%strong
|
||||
#{@path}
|
||||
#{@namespace_name}/#{@path}
|
||||
|
||||
%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.
|
||||
%p
|
||||
You can generate a new export file from your project settings.
|
||||
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.
|
||||
.form-group
|
||||
= hidden_field_tag :namespace_id, @namespace_id
|
||||
= hidden_field_tag :path, @path
|
||||
|
@ -24,4 +22,4 @@
|
|||
= file_field_tag :file, class: ''
|
||||
|
||||
.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 @@
|
|||
%p
|
||||
The errors we encountered were:
|
||||
|
||||
%h3{style: "background: black; color: red;"}
|
||||
#{@errors}
|
||||
%ul
|
||||
- @errors.each do |error|
|
||||
%li
|
||||
error
|
||||
|
|
|
@ -2,4 +2,5 @@ Project <%= @project.name %> couldn't be exported.
|
|||
|
||||
The errors we encountered were:
|
||||
|
||||
<%= @errors %>
|
||||
- @errors.each do |error|
|
||||
<%= error %>
|
|
@ -126,30 +126,35 @@
|
|||
Export project
|
||||
%p.append-bottom-0
|
||||
%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
|
||||
|
||||
= 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"
|
||||
|
||||
%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
|
||||
%p.append-bottom-0
|
||||
%p
|
||||
The following items will be exported:
|
||||
%ul
|
||||
%li Project and wiki repository
|
||||
%li Project and wiki repositories
|
||||
%li Project uploads
|
||||
%li DB items, including configuration
|
||||
%ul
|
||||
- db_export_list.each do |export_relation|
|
||||
%li
|
||||
%code #{export_relation}
|
||||
|
||||
%li Project configuration including web hooks and services
|
||||
%li Issues with comments, merge requests with diffs and comments, labels, milestones, snippets, and other project entities
|
||||
%p
|
||||
The following items will NOT be exported:
|
||||
%ul
|
||||
%li Build traces and artifacts
|
||||
%li LFS objects
|
||||
%hr
|
||||
- if can? current_user, :archive_project, @project
|
||||
.row.prepend-top-default
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
Forking in progress.
|
||||
- else
|
||||
Import in progress.
|
||||
- unless @project.forked? || @project.gitlab_project_import?
|
||||
- if @project.external_import?
|
||||
%p.monospace git clone --bare #{@project.safe_import_url}
|
||||
%p Please wait while we import the repository for you. Refresh at will.
|
||||
:javascript
|
||||
|
|
|
@ -93,7 +93,7 @@
|
|||
- if gitlab_project_import_enabled?
|
||||
= link_to new_import_gitlab_project_path, class: 'btn import_gitlab_project project-submit' do
|
||||
%i.fa.fa-gitlab
|
||||
%span GitLab project
|
||||
%span GitLab export
|
||||
|
||||
.js-toggle-content.hide
|
||||
= render "shared/import_form", f: f
|
||||
|
@ -124,21 +124,33 @@
|
|||
e.preventDefault();
|
||||
var import_modal = $(this).next(".modal").show();
|
||||
});
|
||||
|
||||
$('.modal-header .close').bind('click', function() {
|
||||
$(".modal").hide();
|
||||
});
|
||||
|
||||
$('.import_gitlab_project').bind('click', function() {
|
||||
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('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','');
|
||||
} else {
|
||||
$('.import_gitlab_project').attr('disabled',true);
|
||||
$('.import_gitlab_project').attr('title', 'Project path required.');
|
||||
}
|
||||
})
|
||||
|
||||
$('.import_gitlab_project').click(function( event ) {
|
||||
if($('.import_gitlab_project').attr('disabled')) {
|
||||
event.preventDefault();
|
||||
new Flash("Project path required.", "alert");
|
||||
}
|
||||
});
|
||||
|
||||
$('#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
|
|||
post :toggle_star
|
||||
post :markdown_preview
|
||||
post :export
|
||||
post :remove_export
|
||||
get :download_export
|
||||
get :autocomplete_sources
|
||||
get :activity
|
||||
|
|
|
@ -15,7 +15,7 @@ module Gitlab
|
|||
if check_version! && [project_tree, repo_restorer, wiki_restorer, uploads_restorer].all?(&:restore)
|
||||
project_tree.restored_project
|
||||
else
|
||||
raise Projects::ImportService::Error.new, @shared.errors.join(', ')
|
||||
raise Projects::ImportService::Error.new(@shared.errors.join(', '))
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -11,7 +11,8 @@ module Gitlab
|
|||
end
|
||||
|
||||
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)
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@ module Gitlab
|
|||
'Google Code' => 'google_code',
|
||||
'FogBugz' => 'fogbugz',
|
||||
'Repo by URL' => 'git',
|
||||
'GitLab project' => 'gitlab_project'
|
||||
'GitLab export' => 'gitlab_export'
|
||||
}
|
||||
end
|
||||
|
||||
|
|
|
@ -25,14 +25,14 @@ feature 'project import', feature: true, js: true do
|
|||
|
||||
select2('2', from: '#project_namespace_id')
|
||||
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(URI.parse(current_url).query).to eq('namespace_id=2&path=test-project-path')
|
||||
|
||||
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.issues).not_to be_empty
|
||||
|
|
Loading…
Reference in a new issue