From 1c2554bfd38fc455be16116f6a8cf7700c8db62b Mon Sep 17 00:00:00 2001 From: George Koltsov Date: Fri, 2 Aug 2019 15:34:25 +0100 Subject: Add BitBucketServerImport project filtering --- app/controllers/import/bitbucket_server_controller.rb | 2 +- app/views/import/bitbucket_server/status.html.haml | 4 ++++ lib/bitbucket_server/client.rb | 3 ++- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/app/controllers/import/bitbucket_server_controller.rb b/app/controllers/import/bitbucket_server_controller.rb index f71ea8642cd..f5ea33a8880 100644 --- a/app/controllers/import/bitbucket_server_controller.rb +++ b/app/controllers/import/bitbucket_server_controller.rb @@ -57,7 +57,7 @@ class Import::BitbucketServerController < Import::BaseController # rubocop: disable CodeReuse/ActiveRecord 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: params[:filter_bitbucket_projects]) @repos, @incompatible_repos = @collection.partition { |repo| repo.valid? } # Use the import URL to filter beyond what BaseService#find_already_added_projects diff --git a/app/views/import/bitbucket_server/status.html.haml b/app/views/import/bitbucket_server/status.html.haml index 40609fddbde..29cfa0d3f4c 100644 --- a/app/views/import/bitbucket_server/status.html.haml +++ b/app/views/import/bitbucket_server/status.html.haml @@ -20,6 +20,10 @@ .btn-group = 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_bitbucket_projects, params[:filter_bitbucket_projects], class: 'form-control', placeholder: _('Filter your projects by name'), size: 40 + .table-responsive.prepend-top-10 %table.table.import-jobs %colgroup.import-jobs-from-col diff --git a/lib/bitbucket_server/client.rb b/lib/bitbucket_server/client.rb index 6a608058813..d1661fe92ba 100644 --- a/lib/bitbucket_server/client.rb +++ b/lib/bitbucket_server/client.rb @@ -23,8 +23,9 @@ module BitbucketServer BitbucketServer::Representation::Repo.new(parsed_response) end - def repos(page_offset: 0, limit: nil) + def repos(page_offset: 0, limit: nil, filter: nil) path = "/repos" + path += "?q=name=#{filter}" if filter get_collection(path, :repo, page_offset: page_offset, limit: limit) end -- cgit v1.2.1 From 91353779bfab544f3439cfdff9c6d0db1357166f Mon Sep 17 00:00:00 2001 From: George Koltsov Date: Fri, 2 Aug 2019 16:46:41 +0100 Subject: Add changelog entry --- app/controllers/import/bitbucket_server_controller.rb | 2 +- app/views/import/bitbucket_server/status.html.haml | 13 +++++++------ ...ltsov-51260-add-filtering-to-bitbucket-server-import.yml | 5 +++++ lib/bitbucket_server/client.rb | 2 +- 4 files changed, 14 insertions(+), 8 deletions(-) create mode 100644 changelogs/unreleased/georgekoltsov-51260-add-filtering-to-bitbucket-server-import.yml diff --git a/app/controllers/import/bitbucket_server_controller.rb b/app/controllers/import/bitbucket_server_controller.rb index f5ea33a8880..1956442b72b 100644 --- a/app/controllers/import/bitbucket_server_controller.rb +++ b/app/controllers/import/bitbucket_server_controller.rb @@ -57,7 +57,7 @@ class Import::BitbucketServerController < Import::BaseController # rubocop: disable CodeReuse/ActiveRecord def status - @collection = bitbucket_client.repos(page_offset: page_offset, limit: limit_per_page, filter: params[:filter_bitbucket_projects]) + @collection = bitbucket_client.repos(page_offset: page_offset, limit: limit_per_page, filter: params[:filter]) @repos, @incompatible_repos = @collection.partition { |repo| repo.valid? } # Use the import URL to filter beyond what BaseService#find_already_added_projects diff --git a/app/views/import/bitbucket_server/status.html.haml b/app/views/import/bitbucket_server/status.html.haml index 29cfa0d3f4c..1218462577a 100644 --- a/app/views/import/bitbucket_server/status.html.haml +++ b/app/views/import/bitbucket_server/status.html.haml @@ -17,12 +17,13 @@ = button_tag class: 'btn btn-import btn-success js-import-all' do = _('Import all projects') = icon('spinner spin', class: 'loading-icon') - .btn-group - = 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_bitbucket_projects, params[:filter_bitbucket_projects], class: 'form-control', placeholder: _('Filter your projects by name'), size: 40 +.btn-group + = 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, params[:filter], class: 'form-control append-bottom-10', placeholder: _('Filter your projects by name'), size: 40, autoFocus: true .table-responsive.prepend-top-10 %table.table.import-jobs @@ -66,7 +67,7 @@ = text_field_tag :path, current_user.namespace_path, class: "input-group-text input-large form-control", tabindex: 1, disabled: true %span.input-group-prepend .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 = button_tag class: 'btn btn-import js-add-to-import' do Import diff --git a/changelogs/unreleased/georgekoltsov-51260-add-filtering-to-bitbucket-server-import.yml b/changelogs/unreleased/georgekoltsov-51260-add-filtering-to-bitbucket-server-import.yml new file mode 100644 index 00000000000..3bfbfd11249 --- /dev/null +++ b/changelogs/unreleased/georgekoltsov-51260-add-filtering-to-bitbucket-server-import.yml @@ -0,0 +1,5 @@ +--- +title: Add BitBucket project import filtering +merge_request: 31420 +author: +type: added diff --git a/lib/bitbucket_server/client.rb b/lib/bitbucket_server/client.rb index d1661fe92ba..cf55c692271 100644 --- a/lib/bitbucket_server/client.rb +++ b/lib/bitbucket_server/client.rb @@ -25,7 +25,7 @@ module BitbucketServer def repos(page_offset: 0, limit: nil, filter: nil) path = "/repos" - path += "?q=name=#{filter}" if filter + path += "?name=#{filter}" if filter get_collection(path, :repo, page_offset: page_offset, limit: limit) end -- cgit v1.2.1 From 83cb24358eaf1361b7d7ac0500e35e1392917909 Mon Sep 17 00:00:00 2001 From: George Koltsov Date: Fri, 2 Aug 2019 18:19:15 +0100 Subject: Add i18n strings --- locale/gitlab.pot | 3 +++ 1 file changed, 3 insertions(+) diff --git a/locale/gitlab.pot b/locale/gitlab.pot index b96ceb970ae..8aba22fff14 100644 --- a/locale/gitlab.pot +++ b/locale/gitlab.pot @@ -4936,6 +4936,9 @@ msgstr "" msgid "Filter results by project" msgstr "" +msgid "Filter your projects by name" +msgstr "" + msgid "Filter..." msgstr "" -- cgit v1.2.1 From 13adfb3e7a6458668fd27795dcf8e74004a5860c Mon Sep 17 00:00:00 2001 From: George Koltsov Date: Fri, 2 Aug 2019 18:34:06 +0100 Subject: Add bitbucket_server/client_spec.rb spec --- spec/lib/bitbucket_server/client_spec.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/spec/lib/bitbucket_server/client_spec.rb b/spec/lib/bitbucket_server/client_spec.rb index 988710b7c4d..aa0217856ee 100644 --- a/spec/lib/bitbucket_server/client_spec.rb +++ b/spec/lib/bitbucket_server/client_spec.rb @@ -58,6 +58,17 @@ describe BitbucketServer::Client do subject.repos(page_offset: 10, limit: 25) 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 describe '#create_branch' do -- cgit v1.2.1 From 4e64ca44774ff6d2e23dceabaf0f1117a7ff298f Mon Sep 17 00:00:00 2001 From: George Koltsov Date: Tue, 6 Aug 2019 10:56:54 +0100 Subject: Add BitbucketServerController filtering spec --- ...tsov-51260-add-filtering-to-bitbucket-server-import.yml | 2 +- .../controllers/import/bitbucket_server_controller_spec.rb | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/changelogs/unreleased/georgekoltsov-51260-add-filtering-to-bitbucket-server-import.yml b/changelogs/unreleased/georgekoltsov-51260-add-filtering-to-bitbucket-server-import.yml index 3bfbfd11249..c455b4cf642 100644 --- a/changelogs/unreleased/georgekoltsov-51260-add-filtering-to-bitbucket-server-import.yml +++ b/changelogs/unreleased/georgekoltsov-51260-add-filtering-to-bitbucket-server-import.yml @@ -1,5 +1,5 @@ --- -title: Add BitBucket project import filtering +title: Add BitBucketServer project import filtering merge_request: 31420 author: type: added diff --git a/spec/controllers/import/bitbucket_server_controller_spec.rb b/spec/controllers/import/bitbucket_server_controller_spec.rb index b89d7317b9c..e1aeab46fca 100644 --- a/spec/controllers/import/bitbucket_server_controller_spec.rb +++ b/spec/controllers/import/bitbucket_server_controller_spec.rb @@ -134,6 +134,8 @@ describe Import::BitbucketServerController do describe 'GET status' do render_views + let(:repos) { instance_double(BitbucketServer::Collection) } + before do allow(controller).to receive(:bitbucket_client).and_return(client) @@ -145,7 +147,6 @@ describe Import::BitbucketServerController 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) - repos = instance_double(BitbucketServer::Collection) expect(repos).to receive(:partition).and_return([[@repo, @created_repo], [@invalid_repo]]) expect(repos).to receive(:current_page).and_return(1) @@ -159,6 +160,17 @@ describe Import::BitbucketServerController do expect(assigns(:repos)).to eq([@repo]) expect(assigns(:incompatible_repos)).to eq([@invalid_repo]) 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 describe 'GET jobs' do -- cgit v1.2.1 From 94e1404c4b138ede19611a46a5736764a61cdab7 Mon Sep 17 00:00:00 2001 From: George Koltsov Date: Tue, 6 Aug 2019 11:26:11 +0100 Subject: Update import/bitbucket_server.md docs --- doc/user/project/import/bitbucket_server.md | 6 ++++-- .../img/bitbucket_server_import_select_project.png | Bin 19427 -> 0 bytes .../bitbucket_server_import_select_project_v12_3.png | Bin 0 -> 47059 bytes 3 files changed, 4 insertions(+), 2 deletions(-) delete mode 100644 doc/user/project/import/img/bitbucket_server_import_select_project.png create mode 100644 doc/user/project/import/img/bitbucket_server_import_select_project_v12_3.png diff --git a/doc/user/project/import/bitbucket_server.md b/doc/user/project/import/bitbucket_server.md index 4e1614d82a5..5f426ed7153 100644 --- a/doc/user/project/import/bitbucket_server.md +++ b/doc/user/project/import/bitbucket_server.md @@ -32,6 +32,8 @@ Import your projects from Bitbucket Server to GitLab with minimal effort. 1. Attachments in Markdown are currently not imported. 1. Task lists 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 @@ -68,7 +70,7 @@ namespace that started the import process. ![Grant access](img/bitbucket_server_import_credentials.png) 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. - ![Import projects](img/bitbucket_server_import_select_project.png) + ![Import projects](img/bitbucket_server_import_select_project_v12_3.png) diff --git a/doc/user/project/import/img/bitbucket_server_import_select_project.png b/doc/user/project/import/img/bitbucket_server_import_select_project.png deleted file mode 100644 index e7fddef9955..00000000000 Binary files a/doc/user/project/import/img/bitbucket_server_import_select_project.png and /dev/null differ diff --git a/doc/user/project/import/img/bitbucket_server_import_select_project_v12_3.png b/doc/user/project/import/img/bitbucket_server_import_select_project_v12_3.png new file mode 100644 index 00000000000..1c344853cc8 Binary files /dev/null and b/doc/user/project/import/img/bitbucket_server_import_select_project_v12_3.png differ -- cgit v1.2.1 From 485b8b86edaeed1ba3a8bf55df23ca6cbc1f015b Mon Sep 17 00:00:00 2001 From: George Koltsov Date: Tue, 6 Aug 2019 17:18:53 +0100 Subject: Add filter param sanitization --- app/controllers/import/bitbucket_server_controller.rb | 8 +++++++- app/views/import/bitbucket_server/status.html.haml | 2 +- doc/user/project/import/bitbucket_server.md | 4 ++-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/app/controllers/import/bitbucket_server_controller.rb b/app/controllers/import/bitbucket_server_controller.rb index 1956442b72b..dc72a4e4fd9 100644 --- a/app/controllers/import/bitbucket_server_controller.rb +++ b/app/controllers/import/bitbucket_server_controller.rb @@ -1,6 +1,8 @@ # frozen_string_literal: true class Import::BitbucketServerController < Import::BaseController + include ActionView::Helpers::SanitizeHelper + before_action :verify_bitbucket_server_import_enabled before_action :bitbucket_auth, except: [:new, :configure] before_action :validate_import_params, only: [:create] @@ -57,7 +59,7 @@ class Import::BitbucketServerController < Import::BaseController # rubocop: disable CodeReuse/ActiveRecord def status - @collection = bitbucket_client.repos(page_offset: page_offset, limit: limit_per_page, filter: params[:filter]) + @collection = bitbucket_client.repos(page_offset: page_offset, limit: limit_per_page, filter: sanitized_filter_param) @repos, @incompatible_repos = @collection.partition { |repo| repo.valid? } # Use the import URL to filter beyond what BaseService#find_already_added_projects @@ -147,4 +149,8 @@ class Import::BitbucketServerController < Import::BaseController def limit_per_page BitbucketServer::Paginator::PAGE_LENGTH end + + def sanitized_filter_param + sanitize(params[:filter]) + end end diff --git a/app/views/import/bitbucket_server/status.html.haml b/app/views/import/bitbucket_server/status.html.haml index 1218462577a..aac09801d91 100644 --- a/app/views/import/bitbucket_server/status.html.haml +++ b/app/views/import/bitbucket_server/status.html.haml @@ -23,7 +23,7 @@ .input-btn-group.float-right = form_tag status_import_bitbucket_server_path, :method => 'get' do - = text_field_tag :filter, params[:filter], class: 'form-control append-bottom-10', placeholder: _('Filter your projects by name'), size: 40, autoFocus: true + = 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.table.import-jobs diff --git a/doc/user/project/import/bitbucket_server.md b/doc/user/project/import/bitbucket_server.md index 5f426ed7153..28e211ee2ba 100644 --- a/doc/user/project/import/bitbucket_server.md +++ b/doc/user/project/import/bitbucket_server.md @@ -32,8 +32,8 @@ Import your projects from Bitbucket Server to GitLab with minimal effort. 1. Attachments in Markdown are currently not imported. 1. Task lists 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) +1. Project filtering does not support fuzzy search (only `starts with` or `full + match strings` are currently supported) ## How it works -- cgit v1.2.1