Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG1
-rw-r--r--app/assets/javascripts/importer_status.js16
-rw-r--r--app/assets/stylesheets/pages/projects.scss10
-rw-r--r--app/controllers/import/github_controller.rb7
-rw-r--r--app/helpers/namespaces_helper.rb5
-rw-r--r--app/views/import/github/status.html.haml12
-rw-r--r--doc/workflow/importing/img/import_projects_from_github_importer.pngbin28989 -> 65288 bytes
-rw-r--r--doc/workflow/importing/import_projects_from_github.md5
-rw-r--r--lib/gitlab/github_import/project_creator.rb7
-rw-r--r--spec/controllers/import/github_controller_spec.rb46
-rw-r--r--spec/lib/gitlab/github_import/project_creator_spec.rb2
11 files changed, 82 insertions, 29 deletions
diff --git a/CHANGELOG b/CHANGELOG
index bc19048e94b..e2b70b3f294 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -150,6 +150,7 @@ v 8.12.0 (unreleased)
- Refactor the triggers page and documentation !6217
- Show values of CI trigger variables only when clicked (Katarzyna Kobierska Ula Budziszewska)
- Use default clone protocol on "check out, review, and merge locally" help page URL
+ - Let the user choose a namespace and name on GitHub imports
- API for Ci Lint !5953 (Katarzyna Kobierska Urszula Budziszewska)
- Allow bulk update merge requests from merge requests index page
- Ensure validation messages are shown within the milestone form
diff --git a/app/assets/javascripts/importer_status.js b/app/assets/javascripts/importer_status.js
index 9efad1ce943..4aced1e618f 100644
--- a/app/assets/javascripts/importer_status.js
+++ b/app/assets/javascripts/importer_status.js
@@ -10,24 +10,24 @@
ImporterStatus.prototype.initStatusPage = function() {
$('.js-add-to-import').off('click').on('click', (function(_this) {
return function(e) {
- var $btn, $namespace_input, $target_field, $tr, id, target_namespace;
+ var $btn, $namespace_input, $target_field, $tr, id, target_namespace, newName;
$btn = $(e.currentTarget);
$tr = $btn.closest('tr');
$target_field = $tr.find('.import-target');
- $namespace_input = $target_field.find('input');
+ $namespace_input = $target_field.find('.js-select-namespace option:selected');
id = $tr.attr('id').replace('repo_', '');
target_namespace = null;
-
+ newName = null;
if ($namespace_input.length > 0) {
- target_namespace = $namespace_input.prop('value');
- $target_field.empty().append(target_namespace + "/" + ($target_field.data('project_name')));
+ target_namespace = $namespace_input[0].innerHTML;
+ newName = $target_field.find('#path').prop('value');
+ $target_field.empty().append(target_namespace + "/" + newName);
}
-
$btn.disable().addClass('is-loading');
-
return $.post(_this.import_url, {
repo_id: id,
- target_namespace: target_namespace
+ target_namespace: target_namespace,
+ new_name: newName
}, {
dataType: 'script'
});
diff --git a/app/assets/stylesheets/pages/projects.scss b/app/assets/stylesheets/pages/projects.scss
index db46d8072ce..8c8c403244e 100644
--- a/app/assets/stylesheets/pages/projects.scss
+++ b/app/assets/stylesheets/pages/projects.scss
@@ -770,3 +770,13 @@ pre.light-well {
}
}
}
+
+.project-path {
+ .form-control {
+ min-width: 100px;
+ }
+ .select2-choice {
+ border-top-right-radius: 0;
+ border-bottom-right-radius: 0;
+ }
+} \ No newline at end of file
diff --git a/app/controllers/import/github_controller.rb b/app/controllers/import/github_controller.rb
index 8c6bdd16383..ee7d498c59c 100644
--- a/app/controllers/import/github_controller.rb
+++ b/app/controllers/import/github_controller.rb
@@ -40,11 +40,12 @@ class Import::GithubController < Import::BaseController
def create
@repo_id = params[:repo_id].to_i
repo = client.repo(@repo_id)
- @project_name = repo.name
- @target_namespace = find_or_create_namespace(repo.owner.login, client.user.login)
+ @project_name = params[:new_name].presence || repo.name
+ namespace_path = params[:target_namespace].presence || current_user.namespace_path
+ @target_namespace = find_or_create_namespace(namespace_path, current_user.namespace_path)
if current_user.can?(:create_projects, @target_namespace)
- @project = Gitlab::GithubImport::ProjectCreator.new(repo, @target_namespace, current_user, access_params).execute
+ @project = Gitlab::GithubImport::ProjectCreator.new(repo, @project_name, @target_namespace, current_user, access_params).execute
else
render 'unauthorized'
end
diff --git a/app/helpers/namespaces_helper.rb b/app/helpers/namespaces_helper.rb
index 94c6b548ecd..e0b8dc1393b 100644
--- a/app/helpers/namespaces_helper.rb
+++ b/app/helpers/namespaces_helper.rb
@@ -1,6 +1,9 @@
module NamespacesHelper
- def namespaces_options(selected = :current_user, display_path: false)
+ def namespaces_options(selected = :current_user, display_path: false, extra_group: nil)
groups = current_user.owned_groups + current_user.masters_groups
+
+ groups << extra_group if extra_group && !Group.exists?(name: extra_group.name)
+
users = [current_user.namespace]
data_attr_group = { 'data-options-parent' => 'groups' }
diff --git a/app/views/import/github/status.html.haml b/app/views/import/github/status.html.haml
index bd3be20c4f8..4c721d40b55 100644
--- a/app/views/import/github/status.html.haml
+++ b/app/views/import/github/status.html.haml
@@ -45,7 +45,17 @@
%td
= github_project_link(repo.full_name)
%td.import-target
- = import_project_target(repo.owner.login, repo.name)
+ %fieldset.row
+ .input-group
+ .project-path.input-group-btn
+ - if current_user.can_select_namespace?
+ - selected = params[:namespace_id] || :current_user
+ - opts = current_user.can_create_group? ? { extra_group: Group.new(name: repo.owner.login, path: repo.owner.login) } : {}
+ = select_tag :namespace_id, namespaces_options(selected, opts.merge({ display_path: true })), { class: 'select2 js-select-namespace', tabindex: 1 }
+ - else
+ = text_field_tag :path, current_user.namespace_path, class: "input-large form-control", tabindex: 1, disabled: true
+ %span.input-group-addon /
+ = text_field_tag :path, repo.name, class: "input-mini form-control", tabindex: 2, autofocus: true, required: true
%td.import-actions.job-status
= button_tag class: "btn btn-import js-add-to-import" do
Import
diff --git a/doc/workflow/importing/img/import_projects_from_github_importer.png b/doc/workflow/importing/img/import_projects_from_github_importer.png
index 2082de06f47..eadd33c695f 100644
--- a/doc/workflow/importing/img/import_projects_from_github_importer.png
+++ b/doc/workflow/importing/img/import_projects_from_github_importer.png
Binary files differ
diff --git a/doc/workflow/importing/import_projects_from_github.md b/doc/workflow/importing/import_projects_from_github.md
index dd38fe0bc01..c36dfdb78ec 100644
--- a/doc/workflow/importing/import_projects_from_github.md
+++ b/doc/workflow/importing/import_projects_from_github.md
@@ -106,6 +106,11 @@ If you want, you can import all your GitHub projects in one go by hitting
![GitHub importer page](img/import_projects_from_github_importer.png)
+---
+
+You can also choose a different name for the project and a different namespace,
+if you have the privileges to do so.
+
[gh-import]: ../../integration/github.md "GitHub integration"
[new-project]: ../../gitlab-basics/create-project.md "How to create a new project in GitLab"
[gh-integration]: #authorize-access-to-your-repositories-using-the-github-integration
diff --git a/lib/gitlab/github_import/project_creator.rb b/lib/gitlab/github_import/project_creator.rb
index e9725880c5e..605abfabdab 100644
--- a/lib/gitlab/github_import/project_creator.rb
+++ b/lib/gitlab/github_import/project_creator.rb
@@ -3,8 +3,9 @@ module Gitlab
class ProjectCreator
attr_reader :repo, :namespace, :current_user, :session_data
- def initialize(repo, namespace, current_user, session_data)
+ def initialize(repo, name, namespace, current_user, session_data)
@repo = repo
+ @name = name
@namespace = namespace
@current_user = current_user
@session_data = session_data
@@ -13,8 +14,8 @@ module Gitlab
def execute
project = ::Projects::CreateService.new(
current_user,
- name: repo.name,
- path: repo.name,
+ name: @name,
+ path: @name,
description: repo.description,
namespace_id: namespace.id,
visibility_level: repo.private ? Gitlab::VisibilityLevel::PRIVATE : ApplicationSetting.current.default_project_visibility,
diff --git a/spec/controllers/import/github_controller_spec.rb b/spec/controllers/import/github_controller_spec.rb
index ebfbf54182b..4f96567192d 100644
--- a/spec/controllers/import/github_controller_spec.rb
+++ b/spec/controllers/import/github_controller_spec.rb
@@ -124,8 +124,8 @@ describe Import::GithubController do
context "when the GitHub user and GitLab user's usernames match" do
it "takes the current user's namespace" do
expect(Gitlab::GithubImport::ProjectCreator).
- to receive(:new).with(github_repo, user.namespace, user, access_params).
- and_return(double(execute: true))
+ to receive(:new).with(github_repo, github_repo.name, user.namespace, user, access_params).
+ and_return(double(execute: true))
post :create, format: :js
end
@@ -136,8 +136,8 @@ describe Import::GithubController do
it "takes the current user's namespace" do
expect(Gitlab::GithubImport::ProjectCreator).
- to receive(:new).with(github_repo, user.namespace, user, access_params).
- and_return(double(execute: true))
+ to receive(:new).with(github_repo, github_repo.name, user.namespace, user, access_params).
+ and_return(double(execute: true))
post :create, format: :js
end
@@ -158,8 +158,8 @@ describe Import::GithubController do
context "when the namespace is owned by the GitLab user" do
it "takes the existing namespace" do
expect(Gitlab::GithubImport::ProjectCreator).
- to receive(:new).with(github_repo, existing_namespace, user, access_params).
- and_return(double(execute: true))
+ to receive(:new).with(github_repo, github_repo.name, existing_namespace, user, access_params).
+ and_return(double(execute: true))
post :create, format: :js
end
@@ -171,9 +171,10 @@ describe Import::GithubController do
existing_namespace.save
end
- it "doesn't create a project" do
+ it "creates a project using user's namespace" do
expect(Gitlab::GithubImport::ProjectCreator).
- not_to receive(:new)
+ to receive(:new).with(github_repo, github_repo.name, user.namespace, user, access_params).
+ and_return(double(execute: true))
post :create, format: :js
end
@@ -186,15 +187,15 @@ describe Import::GithubController do
expect(Gitlab::GithubImport::ProjectCreator).
to receive(:new).and_return(double(execute: true))
- expect { post :create, format: :js }.to change(Namespace, :count).by(1)
+ expect { post :create, target_namespace: github_repo.name, format: :js }.to change(Namespace, :count).by(1)
end
it "takes the new namespace" do
expect(Gitlab::GithubImport::ProjectCreator).
- to receive(:new).with(github_repo, an_instance_of(Group), user, access_params).
+ to receive(:new).with(github_repo, github_repo.name, an_instance_of(Group), user, access_params).
and_return(double(execute: true))
- post :create, format: :js
+ post :create, target_namespace: github_repo.name, format: :js
end
end
@@ -212,13 +213,34 @@ describe Import::GithubController do
it "takes the current user's namespace" do
expect(Gitlab::GithubImport::ProjectCreator).
- to receive(:new).with(github_repo, user.namespace, user, access_params).
+ to receive(:new).with(github_repo, github_repo.name, user.namespace, user, access_params).
and_return(double(execute: true))
post :create, format: :js
end
end
end
+
+ context 'user has chosen a namespace and name for the project' do
+ let(:test_namespace) { create(:namespace, name: 'test_namespace', owner: user) }
+ let(:test_name) { 'test_name' }
+
+ it 'takes the selected namespace and name' do
+ expect(Gitlab::GithubImport::ProjectCreator).
+ to receive(:new).with(github_repo, test_name, test_namespace, user, access_params).
+ and_return(double(execute: true))
+
+ post :create, { target_namespace: test_namespace.name, new_name: test_name, format: :js }
+ end
+
+ it 'takes the selected name and default namespace' do
+ expect(Gitlab::GithubImport::ProjectCreator).
+ to receive(:new).with(github_repo, test_name, user.namespace, user, access_params).
+ and_return(double(execute: true))
+
+ post :create, { new_name: test_name, format: :js }
+ end
+ end
end
end
end
diff --git a/spec/lib/gitlab/github_import/project_creator_spec.rb b/spec/lib/gitlab/github_import/project_creator_spec.rb
index 014ee462e5c..ab06b7bc5bb 100644
--- a/spec/lib/gitlab/github_import/project_creator_spec.rb
+++ b/spec/lib/gitlab/github_import/project_creator_spec.rb
@@ -13,7 +13,7 @@ describe Gitlab::GithubImport::ProjectCreator, lib: true do
)
end
- subject(:service) { described_class.new(repo, namespace, user, github_access_token: 'asdffg') }
+ subject(:service) { described_class.new(repo, repo.name, namespace, user, github_access_token: 'asdffg') }
before do
namespace.add_owner(user)