Read about our upcoming Code of Conduct on this issue

Commit f4d2a2d9 authored by Rémy Coutable's avatar Rémy Coutable
Browse files

Merge branch 'fix/import-data-issue' into 'master'

Create import data in service and fix timing issues when scheduling job

Fixes https://gitlab.com/gitlab-org/gitlab-ce/issues/17401

Fixes https://gitlab.com/gitlab-org/gitlab-ce/issues/17376

See merge request !4106
......@@ -64,6 +64,9 @@ v 8.7.6
- Fix links on wiki pages for relative url setups. !4131 (Artem Sidorenko)
- Fix import from gitlab.com to a private instance failure
v 8.7.6
- Fix external imports not finding the import data
v 8.7.5
- Fix relative links in wiki pages. !4050
- Fix always showing build notification message when switching between merge requests !4086
......
......@@ -20,6 +20,7 @@ def create
@project.import_retry
else
@project.import_start
@project.add_import_job
end
end
......
......@@ -204,7 +204,6 @@ def update_forks_visibility_level
state :finished
state :failed
after_transition any => :started, do: :schedule_add_import_job
after_transition any => :finished, do: :clear_import_data
end
......@@ -349,10 +348,6 @@ def saved?
id && persisted?
end
def schedule_add_import_job
run_after_commit(:add_import_job)
end
def add_import_job
if forked?
job_id = RepositoryForkWorker.perform_async(self.id, forked_from_project.path_with_namespace, self.namespace.path)
......
......@@ -6,6 +6,7 @@ def initialize(user, params)
def execute
forked_from_project_id = params.delete(:forked_from_project_id)
import_data = params.delete(:import_data)
@project = Project.new(params)
......@@ -49,16 +50,14 @@ def execute
@project.build_forked_project_link(forked_from_project_id: forked_from_project_id)
end
Project.transaction do
@project.save
save_project_and_import_data(import_data)
if @project.persisted? && !@project.import?
raise 'Failed to create repository' unless @project.create_repository
end
end
@project.import_start if @project.import?
after_create_actions if @project.persisted?
@project.add_import_job if @project.import?
@project
rescue => e
message = "Unable to save project: #{e.message}"
......@@ -93,8 +92,16 @@ def after_create_actions
unless @project.group
@project.team << [current_user, :master, current_user]
end
end
@project.import_start if @project.import?
def save_project_and_import_data(import_data)
Project.transaction do
@project.create_or_update_import_data(data: import_data[:data], credentials: import_data[:credentials]) if import_data
if @project.save && !@project.import?
raise 'Failed to create repository' unless @project.create_repository
end
end
end
end
end
......@@ -11,7 +11,7 @@ def initialize(repo, namespace, current_user, session_data)
end
def execute
project = ::Projects::CreateService.new(
::Projects::CreateService.new(
current_user,
name: repo["name"],
path: repo["slug"],
......@@ -21,11 +21,8 @@ def execute
import_type: "bitbucket",
import_source: "#{repo["owner"]}/#{repo["slug"]}",
import_url: "ssh://git@bitbucket.org/#{repo["owner"]}/#{repo["slug"]}.git",
import_data: { credentials: { bb_session: session_data } }
).execute
project.create_or_update_import_data(credentials: { bb_session: session_data })
project
end
end
end
......
......@@ -12,7 +12,7 @@ def initialize(repo, fb_session, namespace, current_user, user_map = nil)
end
def execute
project = ::Projects::CreateService.new(
::Projects::CreateService.new(
current_user,
name: repo.safe_name,
path: repo.path,
......@@ -21,12 +21,9 @@ def execute
visibility_level: Gitlab::VisibilityLevel::INTERNAL,
import_type: 'fogbugz',
import_source: repo.name,
import_url: Project::UNKNOWN_IMPORT_URL
import_url: Project::UNKNOWN_IMPORT_URL,
import_data: { data: { 'repo' => repo.raw_data, 'user_map' => user_map }, credentials: { fb_session: fb_session } }
).execute
project.create_or_update_import_data(data: { 'repo' => repo.raw_data, 'user_map' => user_map }, credentials: { fb_session: fb_session })
project
end
end
end
......
......@@ -11,7 +11,7 @@ def initialize(repo, namespace, current_user, user_map = nil)
end
def execute
project = ::Projects::CreateService.new(
::Projects::CreateService.new(
current_user,
name: repo.name,
path: repo.name,
......@@ -21,12 +21,9 @@ def execute
visibility_level: Gitlab::VisibilityLevel::PUBLIC,
import_type: "google_code",
import_source: repo.name,
import_url: repo.import_url
import_url: repo.import_url,
import_data: { data: { 'repo' => repo.raw_data, 'user_map' => user_map } }
).execute
project.create_or_update_import_data(data: { 'repo' => repo.raw_data, 'user_map' => user_map })
project
end
end
end
......
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