Commit 6c978c8f authored by Douwe Maan's avatar Douwe Maan

Merge branch...

Merge branch '42327-import-from-gitlab-com-fails-destination-already-exists-and-is-not-an-empty-directory-error' into 'master'

Resolve "Import from GitLab.com fails (destination already exists and is not an empty directory error)."

Closes #42327

See merge request gitlab-org/gitlab-ce!16714
parents 4376be84 41a14498
...@@ -568,6 +568,9 @@ class Project < ActiveRecord::Base ...@@ -568,6 +568,9 @@ class Project < ActiveRecord::Base
RepositoryForkWorker.perform_async(id, RepositoryForkWorker.perform_async(id,
forked_from_project.repository_storage_path, forked_from_project.repository_storage_path,
forked_from_project.disk_path) forked_from_project.disk_path)
elsif gitlab_project_import?
# Do not retry on Import/Export until https://gitlab.com/gitlab-org/gitlab-ce/issues/26189 is solved.
RepositoryImportWorker.set(retry: false).perform_async(self.id)
else else
RepositoryImportWorker.perform_async(self.id) RepositoryImportWorker.perform_async(self.id)
end end
......
...@@ -2,7 +2,7 @@ class EmailsOnPushService < Service ...@@ -2,7 +2,7 @@ class EmailsOnPushService < Service
boolean_accessor :send_from_committer_email boolean_accessor :send_from_committer_email
boolean_accessor :disable_diffs boolean_accessor :disable_diffs
prop_accessor :recipients prop_accessor :recipients
validates :recipients, presence: true, if: :activated? validates :recipients, presence: true, if: :valid_recipients?
def title def title
'Emails on push' 'Emails on push'
......
...@@ -4,7 +4,7 @@ class IrkerService < Service ...@@ -4,7 +4,7 @@ class IrkerService < Service
prop_accessor :server_host, :server_port, :default_irc_uri prop_accessor :server_host, :server_port, :default_irc_uri
prop_accessor :recipients, :channels prop_accessor :recipients, :channels
boolean_accessor :colorize_messages boolean_accessor :colorize_messages
validates :recipients, presence: true, if: :activated? validates :recipients, presence: true, if: :valid_recipients?
before_validation :get_channels before_validation :get_channels
......
class PipelinesEmailService < Service class PipelinesEmailService < Service
prop_accessor :recipients prop_accessor :recipients
boolean_accessor :notify_only_broken_pipelines boolean_accessor :notify_only_broken_pipelines
validates :recipients, presence: true, if: :activated? validates :recipients, presence: true, if: :valid_recipients?
def initialize_properties def initialize_properties
self.properties ||= { notify_only_broken_pipelines: true } self.properties ||= { notify_only_broken_pipelines: true }
......
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
# and implement a set of methods # and implement a set of methods
class Service < ActiveRecord::Base class Service < ActiveRecord::Base
include Sortable include Sortable
include Importable
serialize :properties, JSON # rubocop:disable Cop/ActiveRecordSerialize serialize :properties, JSON # rubocop:disable Cop/ActiveRecordSerialize
default_value_for :active, false default_value_for :active, false
...@@ -295,4 +297,8 @@ class Service < ActiveRecord::Base ...@@ -295,4 +297,8 @@ class Service < ActiveRecord::Base
project.cache_has_external_wiki project.cache_has_external_wiki
end end
end end
def valid_recipients?
activated? && !importing?
end
end end
...@@ -20,7 +20,11 @@ class RepositoryImportWorker ...@@ -20,7 +20,11 @@ class RepositoryImportWorker
# to those importers to mark the import process as complete. # to those importers to mark the import process as complete.
return if service.async? return if service.async?
raise result[:message] if result[:status] == :error if result[:status] == :error
fail_import(project, result[:message]) if project.gitlab_project_import?
raise result[:message]
end
project.after_import project.after_import
end end
...@@ -33,4 +37,8 @@ class RepositoryImportWorker ...@@ -33,4 +37,8 @@ class RepositoryImportWorker
Rails.logger.info("Project #{project.full_path} was in inconsistent state (#{project.import_status}) while importing.") Rails.logger.info("Project #{project.full_path} was in inconsistent state (#{project.import_status}) while importing.")
false false
end end
def fail_import(project, message)
project.mark_import_as_failed(message)
end
end end
---
title: Fixes destination already exists, and some particular service errors on Import/Export
error
merge_request: 16714
author:
type: fixed
...@@ -19,8 +19,13 @@ module Gitlab ...@@ -19,8 +19,13 @@ module Gitlab
def error(error) def error(error)
error_out(error.message, caller[0].dup) error_out(error.message, caller[0].dup)
@errors << error.message @errors << error.message
# Debug: # Debug:
Rails.logger.error(error.backtrace.join("\n")) if error.backtrace
Rails.logger.error("Import/Export backtrace: #{error.backtrace.join("\n")}")
else
Rails.logger.error("No backtrace found")
end
end end
private private
......
...@@ -7096,7 +7096,7 @@ ...@@ -7096,7 +7096,7 @@
"project_id": 5, "project_id": 5,
"created_at": "2016-06-14T15:01:51.232Z", "created_at": "2016-06-14T15:01:51.232Z",
"updated_at": "2016-06-14T15:01:51.232Z", "updated_at": "2016-06-14T15:01:51.232Z",
"active": false, "active": true,
"properties": { "properties": {
}, },
......
...@@ -164,6 +164,10 @@ describe Gitlab::ImportExport::ProjectTreeSaver do ...@@ -164,6 +164,10 @@ describe Gitlab::ImportExport::ProjectTreeSaver do
expect(saved_project_json['services'].first['type']).to eq('CustomIssueTrackerService') expect(saved_project_json['services'].first['type']).to eq('CustomIssueTrackerService')
end end
it 'saves the properties for a service' do
expect(saved_project_json['services'].first['properties']).to eq('one' => 'value')
end
it 'has project feature' do it 'has project feature' do
project_feature = saved_project_json['project_feature'] project_feature = saved_project_json['project_feature']
expect(project_feature).not_to be_empty expect(project_feature).not_to be_empty
...@@ -279,7 +283,7 @@ describe Gitlab::ImportExport::ProjectTreeSaver do ...@@ -279,7 +283,7 @@ describe Gitlab::ImportExport::ProjectTreeSaver do
commit_id: ci_build.pipeline.sha) commit_id: ci_build.pipeline.sha)
create(:event, :created, target: milestone, project: project, author: user) create(:event, :created, target: milestone, project: project, author: user)
create(:service, project: project, type: 'CustomIssueTrackerService', category: 'issue_tracker') create(:service, project: project, type: 'CustomIssueTrackerService', category: 'issue_tracker', properties: { one: 'value' })
create(:project_custom_attribute, project: project) create(:project_custom_attribute, project: project)
create(:project_custom_attribute, project: project) create(:project_custom_attribute, project: project)
......
...@@ -49,9 +49,22 @@ describe RepositoryImportWorker do ...@@ -49,9 +49,22 @@ describe RepositoryImportWorker do
expect do expect do
subject.perform(project.id) subject.perform(project.id)
end.to raise_error(StandardError, error) end.to raise_error(RuntimeError, error)
expect(project.reload.import_jid).not_to be_nil expect(project.reload.import_jid).not_to be_nil
end end
it 'updates the error on Import/Export' do
error = %q{remote: Not Found fatal: repository 'https://user:pass@test.com/root/repoC.git/' not found }
project.update_attributes(import_jid: '123', import_type: 'gitlab_project')
expect_any_instance_of(Projects::ImportService).to receive(:execute).and_return({ status: :error, message: error })
expect do
subject.perform(project.id)
end.to raise_error(RuntimeError, error)
expect(project.reload.import_error).not_to be_nil
end
end end
context 'when using an asynchronous importer' do context 'when using an asynchronous importer' do
......
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