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 {
};
</script>
<template>
<import-projects-table provider-title="providerTitle">
<import-projects-table :provider-title="providerTitle">
<template #actions>
<slot name="actions"></slot>
</template>
......
......@@ -35,8 +35,8 @@ class ImporterStatus {
const $tr = $btn.closest('tr');
const $targetField = $tr.find('.import-target');
const $namespaceInput = $targetField.find('.js-select-namespace option:selected');
const id = $tr.attr('id').replace('repo_', '');
const repoData = $tr.data();
const id = repoData.id || $tr.attr('id').replace('repo_', '');
let targetNamespace;
let newName;
......@@ -63,7 +63,7 @@ class ImporterStatus {
return axios
.post(this.importUrl, attributes)
.then(({ data }) => {
const job = $(`tr#repo_${id}`);
const job = $tr;
job.attr('id', `project_${data.id}`);
job.find('.import-target').html(`<a href="${data.full_path}">${data.full_path}</a>`);
......@@ -86,7 +86,7 @@ class ImporterStatus {
.catch(error => {
let details = error;
const $statusField = $(`#repo_${this.id} .job-status`);
const $statusField = $tr.find('.job-status');
$statusField.text(__('Failed'));
if (error.response && error.response.data && error.response.data.errors) {
......
......@@ -7,6 +7,7 @@ class Import::BitbucketServerController < Import::BaseController
before_action :verify_bitbucket_server_import_enabled
before_action :bitbucket_auth, except: [:new, :configure]
before_action :normalize_import_params, only: [:create]
before_action :validate_import_params, only: [:create]
rescue_from BitbucketServer::Connection::ConnectionError, with: :bitbucket_connection_error
......@@ -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
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
@project_key = params[:bitbucketServerProject]
@repo_slug = params[:bitbucketServerRepo]
@project_key = params[:bitbucket_server_project]
@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 repository slug') unless @repo_slug.present?
......
......@@ -19,7 +19,11 @@ module ImportHelper
end
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
def import_will_timeout_message(_ci_cd_only)
......
......@@ -59,11 +59,11 @@ module Import
end
def repo_slug
@repo_slug ||= params[:bitbucket_server_repo] || params[:bitbucketServerRepo]
@repo_slug ||= params[:bitbucket_server_repo]
end
def project_key
@project_key ||= params[:bitbucket_server_project] || params[:bitbucketServerProject]
@project_key ||= params[:bitbucket_server_project]
end
def url
......
......@@ -55,7 +55,7 @@
= project.human_import_status_name
- @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
= sanitize(link_to(repo.browse_url, repo.browse_url, target: '_blank', rel: 'noopener noreferrer'), attributes: %w(href target rel))
%td.import-target
......
......@@ -6,6 +6,7 @@ RSpec.describe Import::BitbucketServerController do
let(:user) { create(:user) }
let(:project_key) { 'test-project' }
let(:repo_slug) { 'some-repo' }
let(:repo_id) { "#{project_key}/#{repo_slug}" }
let(:client) { instance_double(BitbucketServer::Client) }
def assign_session_tokens
......@@ -46,7 +47,7 @@ RSpec.describe Import::BitbucketServerController do
.to receive(:new).with(project_key, repo_slug, anything, project_name, user.namespace, user, anything)
.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)
end
......@@ -59,20 +60,20 @@ RSpec.describe Import::BitbucketServerController do
.to receive(:new).with(project_key, repo_slug, anything, project_name, user.namespace, user, anything)
.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)
end
end
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)
end
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)
end
......@@ -80,7 +81,7 @@ RSpec.describe Import::BitbucketServerController 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)
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)
end
......@@ -90,15 +91,15 @@ RSpec.describe Import::BitbucketServerController do
.to receive(:new).with(project_key, repo_slug, anything, project_name, user.namespace, user, anything)
.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)
end
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)
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