Commit 028e1fd1 authored by Sean McGivern's avatar Sean McGivern

Merge branch 'xanf-fix-bitbucket-server-importer' into 'master'

Fix bitbucket server import interaction with :new_import_ui feature flag

See merge request gitlab-org/gitlab!36313
parents e20b5649 9f95fe18
...@@ -28,7 +28,7 @@ export default { ...@@ -28,7 +28,7 @@ export default {
}; };
</script> </script>
<template> <template>
<import-projects-table provider-title="providerTitle"> <import-projects-table :provider-title="providerTitle">
<template #actions> <template #actions>
<slot name="actions"></slot> <slot name="actions"></slot>
</template> </template>
......
...@@ -35,8 +35,8 @@ class ImporterStatus { ...@@ -35,8 +35,8 @@ class ImporterStatus {
const $tr = $btn.closest('tr'); const $tr = $btn.closest('tr');
const $targetField = $tr.find('.import-target'); const $targetField = $tr.find('.import-target');
const $namespaceInput = $targetField.find('.js-select-namespace option:selected'); const $namespaceInput = $targetField.find('.js-select-namespace option:selected');
const id = $tr.attr('id').replace('repo_', '');
const repoData = $tr.data(); const repoData = $tr.data();
const id = repoData.id || $tr.attr('id').replace('repo_', '');
let targetNamespace; let targetNamespace;
let newName; let newName;
...@@ -63,7 +63,7 @@ class ImporterStatus { ...@@ -63,7 +63,7 @@ class ImporterStatus {
return axios return axios
.post(this.importUrl, attributes) .post(this.importUrl, attributes)
.then(({ data }) => { .then(({ data }) => {
const job = $(`tr#repo_${id}`); const job = $tr;
job.attr('id', `project_${data.id}`); job.attr('id', `project_${data.id}`);
job.find('.import-target').html(`<a href="${data.full_path}">${data.full_path}</a>`); job.find('.import-target').html(`<a href="${data.full_path}">${data.full_path}</a>`);
...@@ -86,7 +86,7 @@ class ImporterStatus { ...@@ -86,7 +86,7 @@ class ImporterStatus {
.catch(error => { .catch(error => {
let details = error; let details = error;
const $statusField = $(`#repo_${this.id} .job-status`); const $statusField = $tr.find('.job-status');
$statusField.text(__('Failed')); $statusField.text(__('Failed'));
if (error.response && error.response.data && error.response.data.errors) { if (error.response && error.response.data && error.response.data.errors) {
......
...@@ -7,6 +7,7 @@ class Import::BitbucketServerController < Import::BaseController ...@@ -7,6 +7,7 @@ class Import::BitbucketServerController < Import::BaseController
before_action :verify_bitbucket_server_import_enabled before_action :verify_bitbucket_server_import_enabled
before_action :bitbucket_auth, except: [:new, :configure] before_action :bitbucket_auth, except: [:new, :configure]
before_action :normalize_import_params, only: [:create]
before_action :validate_import_params, only: [:create] before_action :validate_import_params, only: [:create]
rescue_from BitbucketServer::Connection::ConnectionError, with: :bitbucket_connection_error rescue_from BitbucketServer::Connection::ConnectionError, with: :bitbucket_connection_error
...@@ -118,9 +119,15 @@ class Import::BitbucketServerController < Import::BaseController ...@@ -118,9 +119,15 @@ class Import::BitbucketServerController < Import::BaseController
@bitbucket_repos ||= client.repos(page_offset: page_offset, limit: limit_per_page, filter: sanitized_filter_param).to_a @bitbucket_repos ||= client.repos(page_offset: page_offset, limit: limit_per_page, filter: sanitized_filter_param).to_a
end end
def normalize_import_params
project_key, repo_slug = params[:repo_id].split('/')
params[:bitbucket_server_project] = project_key
params[:bitbucket_server_repo] = repo_slug
end
def validate_import_params def validate_import_params
@project_key = params[:bitbucketServerProject] @project_key = params[:bitbucket_server_project]
@repo_slug = params[:bitbucketServerRepo] @repo_slug = params[:bitbucket_server_repo]
return render_validation_error('Missing project key') unless @project_key.present? && @repo_slug.present? return render_validation_error('Missing project key') unless @project_key.present? && @repo_slug.present?
return render_validation_error('Missing repository slug') unless @repo_slug.present? return render_validation_error('Missing repository slug') unless @repo_slug.present?
......
...@@ -19,7 +19,11 @@ module ImportHelper ...@@ -19,7 +19,11 @@ module ImportHelper
end end
def provider_project_link_url(provider_url, full_path) def provider_project_link_url(provider_url, full_path)
Gitlab::Utils.append_path(provider_url, full_path) if Gitlab::Utils.parse_url(full_path)&.absolute?
full_path
else
Gitlab::Utils.append_path(provider_url, full_path)
end
end end
def import_will_timeout_message(_ci_cd_only) def import_will_timeout_message(_ci_cd_only)
......
...@@ -59,11 +59,11 @@ module Import ...@@ -59,11 +59,11 @@ module Import
end end
def repo_slug def repo_slug
@repo_slug ||= params[:bitbucket_server_repo] || params[:bitbucketServerRepo] @repo_slug ||= params[:bitbucket_server_repo]
end end
def project_key def project_key
@project_key ||= params[:bitbucket_server_project] || params[:bitbucketServerProject] @project_key ||= params[:bitbucket_server_project]
end end
def url def url
......
...@@ -55,7 +55,7 @@ ...@@ -55,7 +55,7 @@
= project.human_import_status_name = project.human_import_status_name
- @repos.each do |repo| - @repos.each do |repo|
%tr{ id: "repo_#{repo.project_key}___#{repo.slug}", data: { bitbucket_server_project: repo.project_key, bitbucket_server_repo: repo.slug } } %tr{ data: { id: "#{repo.project_key}/#{repo.slug}" } }
%td %td
= sanitize(link_to(repo.browse_url, repo.browse_url, target: '_blank', rel: 'noopener noreferrer'), attributes: %w(href target rel)) = sanitize(link_to(repo.browse_url, repo.browse_url, target: '_blank', rel: 'noopener noreferrer'), attributes: %w(href target rel))
%td.import-target %td.import-target
......
...@@ -6,6 +6,7 @@ RSpec.describe Import::BitbucketServerController do ...@@ -6,6 +6,7 @@ RSpec.describe Import::BitbucketServerController do
let(:user) { create(:user) } let(:user) { create(:user) }
let(:project_key) { 'test-project' } let(:project_key) { 'test-project' }
let(:repo_slug) { 'some-repo' } let(:repo_slug) { 'some-repo' }
let(:repo_id) { "#{project_key}/#{repo_slug}" }
let(:client) { instance_double(BitbucketServer::Client) } let(:client) { instance_double(BitbucketServer::Client) }
def assign_session_tokens def assign_session_tokens
...@@ -46,7 +47,7 @@ RSpec.describe Import::BitbucketServerController do ...@@ -46,7 +47,7 @@ RSpec.describe Import::BitbucketServerController do
.to receive(:new).with(project_key, repo_slug, anything, project_name, user.namespace, user, anything) .to receive(:new).with(project_key, repo_slug, anything, project_name, user.namespace, user, anything)
.and_return(double(execute: project)) .and_return(double(execute: project))
post :create, params: { bitbucketServerProject: project_key, bitbucketServerRepo: repo_slug }, format: :json post :create, params: { repo_id: repo_id }, format: :json
expect(response).to have_gitlab_http_status(:ok) expect(response).to have_gitlab_http_status(:ok)
end end
...@@ -59,20 +60,20 @@ RSpec.describe Import::BitbucketServerController do ...@@ -59,20 +60,20 @@ RSpec.describe Import::BitbucketServerController do
.to receive(:new).with(project_key, repo_slug, anything, project_name, user.namespace, user, anything) .to receive(:new).with(project_key, repo_slug, anything, project_name, user.namespace, user, anything)
.and_return(double(execute: project)) .and_return(double(execute: project))
post :create, params: { bitbucketServerProject: project_key, bitbucketServerRepo: repo_slug, format: :json } post :create, params: { repo_id: repo_id }, format: :json
expect(response).to have_gitlab_http_status(:ok) expect(response).to have_gitlab_http_status(:ok)
end end
end end
it 'returns an error when an invalid project key is used' do it 'returns an error when an invalid project key is used' do
post :create, params: { bitbucket_server_project: 'some&project' } post :create, params: { repo_id: 'some&project/repo' }
expect(response).to have_gitlab_http_status(:unprocessable_entity) expect(response).to have_gitlab_http_status(:unprocessable_entity)
end end
it 'returns an error when an invalid repository slug is used' do it 'returns an error when an invalid repository slug is used' do
post :create, params: { bitbucket_server_project: 'some-project', bitbucket_server_repo: 'try*this' } post :create, params: { repo_id: 'some-project/try*this' }
expect(response).to have_gitlab_http_status(:unprocessable_entity) expect(response).to have_gitlab_http_status(:unprocessable_entity)
end end
...@@ -80,7 +81,7 @@ RSpec.describe Import::BitbucketServerController do ...@@ -80,7 +81,7 @@ RSpec.describe Import::BitbucketServerController do
it 'returns an error when the project cannot be found' do it 'returns an error when the project cannot be found' do
allow(client).to receive(:repo).with(project_key, repo_slug).and_return(nil) allow(client).to receive(:repo).with(project_key, repo_slug).and_return(nil)
post :create, params: { bitbucket_server_project: project_key, bitbucket_server_repo: repo_slug }, format: :json post :create, params: { repo_id: repo_id }, format: :json
expect(response).to have_gitlab_http_status(:unprocessable_entity) expect(response).to have_gitlab_http_status(:unprocessable_entity)
end end
...@@ -90,15 +91,15 @@ RSpec.describe Import::BitbucketServerController do ...@@ -90,15 +91,15 @@ RSpec.describe Import::BitbucketServerController do
.to receive(:new).with(project_key, repo_slug, anything, project_name, user.namespace, user, anything) .to receive(:new).with(project_key, repo_slug, anything, project_name, user.namespace, user, anything)
.and_return(double(execute: build(:project))) .and_return(double(execute: build(:project)))
post :create, params: { bitbucket_server_project: project_key, bitbucket_server_repo: repo_slug }, format: :json post :create, params: { repo_id: repo_id }, format: :json
expect(response).to have_gitlab_http_status(:unprocessable_entity) expect(response).to have_gitlab_http_status(:unprocessable_entity)
end end
it "returns an error when the server can't be contacted" do it "returns an error when the server can't be contacted" do
allow(client).to receive(:repo).with(project_key, repo_slug).and_return([nil, nil]) allow(client).to receive(:repo).with(project_key, repo_slug).and_raise(::BitbucketServer::Connection::ConnectionError)
post :create, params: { bitbucket_server_project: project_key, bitbucket_server_repo: repo_slug }, format: :json post :create, params: { repo_id: repo_id }, format: :json
expect(response).to have_gitlab_http_status(:unprocessable_entity) expect(response).to have_gitlab_http_status(:unprocessable_entity)
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