Commit d2ecbd74 authored by Tim Zallmann's avatar Tim Zallmann

Merge branch 'georgekoltsov/51260-add-filtering-to-bitbucket-server-import' into 'master'

Add BitBucketServerImport project filtering

See merge request gitlab-org/gitlab-ce!31420
parents 832824f4 485b8b86
# frozen_string_literal: true # frozen_string_literal: true
class Import::BitbucketServerController < Import::BaseController class Import::BitbucketServerController < Import::BaseController
include ActionView::Helpers::SanitizeHelper
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 :validate_import_params, only: [:create] before_action :validate_import_params, only: [:create]
...@@ -57,7 +59,7 @@ class Import::BitbucketServerController < Import::BaseController ...@@ -57,7 +59,7 @@ class Import::BitbucketServerController < Import::BaseController
# rubocop: disable CodeReuse/ActiveRecord # rubocop: disable CodeReuse/ActiveRecord
def status def status
@collection = bitbucket_client.repos(page_offset: page_offset, limit: limit_per_page) @collection = bitbucket_client.repos(page_offset: page_offset, limit: limit_per_page, filter: sanitized_filter_param)
@repos, @incompatible_repos = @collection.partition { |repo| repo.valid? } @repos, @incompatible_repos = @collection.partition { |repo| repo.valid? }
# Use the import URL to filter beyond what BaseService#find_already_added_projects # Use the import URL to filter beyond what BaseService#find_already_added_projects
...@@ -147,4 +149,8 @@ class Import::BitbucketServerController < Import::BaseController ...@@ -147,4 +149,8 @@ class Import::BitbucketServerController < Import::BaseController
def limit_per_page def limit_per_page
BitbucketServer::Paginator::PAGE_LENGTH BitbucketServer::Paginator::PAGE_LENGTH
end end
def sanitized_filter_param
sanitize(params[:filter])
end
end end
...@@ -17,9 +17,14 @@ ...@@ -17,9 +17,14 @@
= button_tag class: 'btn btn-import btn-success js-import-all' do = button_tag class: 'btn btn-import btn-success js-import-all' do
= _('Import all projects') = _('Import all projects')
= icon('spinner spin', class: 'loading-icon') = icon('spinner spin', class: 'loading-icon')
.btn-group
.btn-group
= link_to('Reconfigure', configure_import_bitbucket_server_path, class: 'btn btn-primary', method: :post) = link_to('Reconfigure', configure_import_bitbucket_server_path, class: 'btn btn-primary', method: :post)
.input-btn-group.float-right
= form_tag status_import_bitbucket_server_path, :method => 'get' do
= text_field_tag :filter, sanitize(params[:filter]), class: 'form-control append-bottom-10', placeholder: _('Filter your projects by name'), size: 40, autoFocus: true
.table-responsive.prepend-top-10 .table-responsive.prepend-top-10
%table.table.import-jobs %table.table.import-jobs
%colgroup.import-jobs-from-col %colgroup.import-jobs-from-col
...@@ -62,7 +67,7 @@ ...@@ -62,7 +67,7 @@
= text_field_tag :path, current_user.namespace_path, class: "input-group-text input-large form-control", tabindex: 1, disabled: true = text_field_tag :path, current_user.namespace_path, class: "input-group-text input-large form-control", tabindex: 1, disabled: true
%span.input-group-prepend %span.input-group-prepend
.input-group-text / .input-group-text /
= text_field_tag :path, sanitize_project_name(repo.slug), class: "input-mini form-control", tabindex: 2, autofocus: true, required: true = text_field_tag :path, sanitize_project_name(repo.slug), class: "input-mini form-control", tabindex: 2, required: true
%td.import-actions.job-status %td.import-actions.job-status
= button_tag class: 'btn btn-import js-add-to-import' do = button_tag class: 'btn btn-import js-add-to-import' do
Import Import
......
---
title: Add BitBucketServer project import filtering
merge_request: 31420
author:
type: added
...@@ -32,6 +32,8 @@ Import your projects from Bitbucket Server to GitLab with minimal effort. ...@@ -32,6 +32,8 @@ Import your projects from Bitbucket Server to GitLab with minimal effort.
1. Attachments in Markdown are currently not imported. 1. Attachments in Markdown are currently not imported.
1. Task lists are not imported. 1. Task lists are not imported.
1. Emoji reactions are not imported 1. Emoji reactions are not imported
1. Project filtering does not support fuzzy search (only `starts with` or `full
match strings` are currently supported)
## How it works ## How it works
...@@ -68,7 +70,7 @@ namespace that started the import process. ...@@ -68,7 +70,7 @@ namespace that started the import process.
![Grant access](img/bitbucket_server_import_credentials.png) ![Grant access](img/bitbucket_server_import_credentials.png)
1. Click on the projects that you'd like to import or **Import all projects**. 1. Click on the projects that you'd like to import or **Import all projects**.
You can also select the namespace under which each project will be You can also filter projects by name and select the namespace under which each project will be
imported. imported.
![Import projects](img/bitbucket_server_import_select_project.png) ![Import projects](img/bitbucket_server_import_select_project_v12_3.png)
...@@ -23,8 +23,9 @@ module BitbucketServer ...@@ -23,8 +23,9 @@ module BitbucketServer
BitbucketServer::Representation::Repo.new(parsed_response) BitbucketServer::Representation::Repo.new(parsed_response)
end end
def repos(page_offset: 0, limit: nil) def repos(page_offset: 0, limit: nil, filter: nil)
path = "/repos" path = "/repos"
path += "?name=#{filter}" if filter
get_collection(path, :repo, page_offset: page_offset, limit: limit) get_collection(path, :repo, page_offset: page_offset, limit: limit)
end end
......
...@@ -4936,6 +4936,9 @@ msgstr "" ...@@ -4936,6 +4936,9 @@ msgstr ""
msgid "Filter results by project" msgid "Filter results by project"
msgstr "" msgstr ""
msgid "Filter your projects by name"
msgstr ""
msgid "Filter..." msgid "Filter..."
msgstr "" msgstr ""
......
...@@ -134,6 +134,8 @@ describe Import::BitbucketServerController do ...@@ -134,6 +134,8 @@ describe Import::BitbucketServerController do
describe 'GET status' do describe 'GET status' do
render_views render_views
let(:repos) { instance_double(BitbucketServer::Collection) }
before do before do
allow(controller).to receive(:bitbucket_client).and_return(client) allow(controller).to receive(:bitbucket_client).and_return(client)
...@@ -145,7 +147,6 @@ describe Import::BitbucketServerController do ...@@ -145,7 +147,6 @@ describe Import::BitbucketServerController do
it 'assigns repository categories' do it 'assigns repository categories' do
created_project = create(:project, :import_finished, import_type: 'bitbucket_server', creator_id: user.id, import_source: @created_repo.browse_url) created_project = create(:project, :import_finished, import_type: 'bitbucket_server', creator_id: user.id, import_source: @created_repo.browse_url)
repos = instance_double(BitbucketServer::Collection)
expect(repos).to receive(:partition).and_return([[@repo, @created_repo], [@invalid_repo]]) expect(repos).to receive(:partition).and_return([[@repo, @created_repo], [@invalid_repo]])
expect(repos).to receive(:current_page).and_return(1) expect(repos).to receive(:current_page).and_return(1)
...@@ -159,6 +160,17 @@ describe Import::BitbucketServerController do ...@@ -159,6 +160,17 @@ describe Import::BitbucketServerController do
expect(assigns(:repos)).to eq([@repo]) expect(assigns(:repos)).to eq([@repo])
expect(assigns(:incompatible_repos)).to eq([@invalid_repo]) expect(assigns(:incompatible_repos)).to eq([@invalid_repo])
end end
context 'when filtering' do
let(:filter) { 'test' }
it 'passes filter param to bitbucket client' do
expect(repos).to receive(:partition).and_return([[@repo, @created_repo], [@invalid_repo]])
expect(client).to receive(:repos).with(filter: filter, limit: 25, page_offset: 0).and_return(repos)
get :status, params: { filter: filter }, as: :json
end
end
end end
describe 'GET jobs' do describe 'GET jobs' do
......
...@@ -58,6 +58,17 @@ describe BitbucketServer::Client do ...@@ -58,6 +58,17 @@ describe BitbucketServer::Client do
subject.repos(page_offset: 10, limit: 25) subject.repos(page_offset: 10, limit: 25)
end end
context 'when filter param is passed' do
let(:filter) { 'test' }
let(:expected_path) { "#{path}?name=#{filter}" }
it 'requests a collection with filter applied' do
expect(BitbucketServer::Paginator).to receive(:new).with(anything, expected_path, :repo, page_offset: 0, limit: nil)
subject.repos(filter: filter)
end
end
end end
describe '#create_branch' do describe '#create_branch' 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