Commit 680c5313 authored by Stan Hu's avatar Stan Hu

Ensure import by URL works after a failed import

If a project fails to import a project with one of the built-in
importers (e.g. GitHub, Bitbucket, GitLab project templates, etc.), a
user will be redirected to the `/import/new` page. The user can attempt
to import with a Git repository URL, but that would also fail because
`import_type` remained what it was set to initially
(e.g. `gitlab_project`). This caused `ImportService` to use the previous
importer instead of attempting to use the URL.

To fix this problem, we set `import_type` to `git` whenever the import
by URL parameters are used. This is mapped to a `nil` importer in
`Gitlab::ImportSources`.

Closes https://gitlab.com/gitlab-org/gitlab/-/issues/31589
parent 19769be8
......@@ -4,7 +4,13 @@ module ImportUrlParams
def import_url_params
return {} unless params.dig(:project, :import_url).present?
{ import_url: import_params_to_full_url(params[:project]) }
{
import_url: import_params_to_full_url(params[:project]),
# We need to set import_type because attempting to retry an import by URL
# could leave a stale value around. This would erroneously cause an importer
# (e.g. import/export) to run.
import_type: 'git'
}
end
def import_params_to_full_url(params)
......
---
title: Ensure import by URL works after a failed import
merge_request: 27546
author:
type: fixed
......@@ -31,7 +31,8 @@ describe ImportUrlParams do
describe '#import_url_params' do
it 'returns hash with import_url' do
expect(import_url_params).to eq(
import_url: "https://user:password@url.com"
import_url: "https://user:password@url.com",
import_type: 'git'
)
end
end
......@@ -48,7 +49,8 @@ describe ImportUrlParams do
describe '#import_url_params' do
it 'does not change the url' do
expect(import_url_params).to eq(
import_url: "https://user:password@url.com"
import_url: "https://user:password@url.com",
import_type: 'git'
)
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