diff options
-rw-r--r-- | app/assets/javascripts/importer_status.js.coffee | 31 | ||||
-rw-r--r-- | app/controllers/import/base_controller.rb | 21 | ||||
-rw-r--r-- | app/controllers/import/github_controller.rb | 22 | ||||
-rw-r--r-- | app/controllers/import/gitlab_controller.rb | 20 | ||||
-rw-r--r-- | app/views/import/base/create.js.haml (renamed from app/views/import/github/create.js.haml) | 0 | ||||
-rw-r--r-- | app/views/import/github/status.html.haml | 28 | ||||
-rw-r--r-- | app/views/import/gitlab/create.js.haml | 18 | ||||
-rw-r--r-- | app/views/import/gitlab/status.html.haml | 28 | ||||
-rw-r--r-- | app/views/projects/_github_import_modal.html.haml | 15 | ||||
-rw-r--r-- | app/views/projects/_gitlab_import_modal.html.haml | 15 | ||||
-rw-r--r-- | app/views/projects/new.html.haml | 8 | ||||
-rw-r--r-- | app/workers/repository_import_worker.rb | 14 | ||||
-rw-r--r-- | lib/gitlab/github_import/importer.rb | 3 | ||||
-rw-r--r-- | lib/gitlab/gitlab_import/importer.rb | 2 |
14 files changed, 85 insertions, 140 deletions
diff --git a/app/assets/javascripts/importer_status.js.coffee b/app/assets/javascripts/importer_status.js.coffee new file mode 100644 index 00000000000..268efd7c832 --- /dev/null +++ b/app/assets/javascripts/importer_status.js.coffee @@ -0,0 +1,31 @@ +class @ImporterStatus + constructor: (@jobs_url, @import_url) -> + this.initStatusPage() + this.setAutoUpdate() + + initStatusPage: -> + $(".btn-add-to-import").click (event) => + new_namespace = null + tr = $(event.currentTarget).closest("tr") + id = tr.attr("id").replace("repo_", "") + if tr.find(".import-target input").length > 0 + new_namespace = tr.find(".import-target input").prop("value") + tr.find(".import-target").empty().append(new_namespace + "/" + tr.find(".import-target").data("project_name")) + $.post @import_url, {repo_id: id, new_namespace: new_namespace}, dataType: 'script' + + setAutoUpdate: -> + setInterval (=> + $.get @jobs_url, (data) => + $.each data, (i, job) => + job_item = $("#project_" + job.id) + status_field = job_item.find(".job-status") + + if job.import_status == 'finished' + job_item.removeClass("active").addClass("success") + status_field.html('<span class="cgreen"><i class="fa fa-check"></i> done</span>') + else if job.import_status == 'started' + status_field.html("<i class='fa fa-spinner fa-spin'></i> started") + else + status_field.html(job.import_status) + + ), 4000
\ No newline at end of file diff --git a/app/controllers/import/base_controller.rb b/app/controllers/import/base_controller.rb new file mode 100644 index 00000000000..4df171dbcfe --- /dev/null +++ b/app/controllers/import/base_controller.rb @@ -0,0 +1,21 @@ +class Import::BaseController < ApplicationController + + private + + def get_or_create_namespace + existing_namespace = Namespace.find_by("path = ? OR name = ?", @target_namespace, @target_namespace) + + if existing_namespace + if existing_namespace.owner == current_user + namespace = existing_namespace + else + @already_been_taken = true + return false + end + else + namespace = Group.create(name: @target_namespace, path: @target_namespace, owner: current_user) + namespace.add_owner(current_user) + namespace + end + end +end diff --git a/app/controllers/import/github_controller.rb b/app/controllers/import/github_controller.rb index 08419a37476..108fc4396a6 100644 --- a/app/controllers/import/github_controller.rb +++ b/app/controllers/import/github_controller.rb @@ -1,4 +1,4 @@ -class Import::GithubController < ApplicationController +class Import::GithubController < Import::BaseController before_filter :github_auth, except: :callback rescue_from Octokit::Unauthorized, with: :github_unauthorized @@ -30,22 +30,10 @@ class Import::GithubController < ApplicationController def create @repo_id = params[:repo_id].to_i repo = octo_client.repo(@repo_id) - target_namespace = params[:new_namespace].presence || repo.owner.login - existing_namespace = Namespace.find_by("path = ? OR name = ?", target_namespace, target_namespace) - - if existing_namespace - if existing_namespace.owner == current_user - namespace = existing_namespace - else - @already_been_taken = true - @target_namespace = target_namespace - @project_name = repo.name - render and return - end - else - namespace = Group.create(name: target_namespace, path: target_namespace, owner: current_user) - namespace.add_owner(current_user) - end + @target_namespace = params[:new_namespace].presence || repo.owner.login + @project_name = repo.name + + namespace = get_or_create_namespace || (render and return) @project = Gitlab::GithubImport::ProjectCreator.new(repo, namespace, current_user).execute end diff --git a/app/controllers/import/gitlab_controller.rb b/app/controllers/import/gitlab_controller.rb index 448fe6417be..a51ea36aff8 100644 --- a/app/controllers/import/gitlab_controller.rb +++ b/app/controllers/import/gitlab_controller.rb @@ -1,4 +1,4 @@ -class Import::GitlabController < ApplicationController +class Import::GitlabController < Import::BaseController before_filter :gitlab_auth, except: :callback rescue_from OAuth2::Error, with: :gitlab_unauthorized @@ -27,22 +27,10 @@ class Import::GitlabController < ApplicationController def create @repo_id = params[:repo_id].to_i repo = client.project(@repo_id) - target_namespace = params[:new_namespace].presence || repo["namespace"]["path"] - existing_namespace = Namespace.find_by("path = ? OR name = ?", target_namespace, target_namespace) + @target_namespace = params[:new_namespace].presence || repo["namespace"]["path"] + @project_name = repo["name"] - if existing_namespace - if existing_namespace.owner == current_user - namespace = existing_namespace - else - @already_been_taken = true - @target_namespace = target_namespace - @project_name = repo["path"] - render and return - end - else - namespace = Group.create(name: target_namespace, path: target_namespace, owner: current_user) - namespace.add_owner(current_user) - end + namespace = get_or_create_namespace || (render and return) @project = Gitlab::GitlabImport::ProjectCreator.new(repo, namespace, current_user).execute end diff --git a/app/views/import/github/create.js.haml b/app/views/import/base/create.js.haml index cd4c9fbf360..cd4c9fbf360 100644 --- a/app/views/import/github/create.js.haml +++ b/app/views/import/base/create.js.haml diff --git a/app/views/import/github/status.html.haml b/app/views/import/github/status.html.haml index 9797f5983ea..1676c3c26ae 100644 --- a/app/views/import/github/status.html.haml +++ b/app/views/import/github/status.html.haml @@ -34,30 +34,6 @@ %td.import-actions.job-status = button_tag "Add", class: "btn btn-add-to-import" - :coffeescript - $(".btn-add-to-import").click () -> - new_namespace = null - tr = $(this).closest("tr") - id = tr.attr("id").replace("repo_", "") - if tr.find(".import-target input").length > 0 - new_namespace = tr.find(".import-target input").prop("value") - tr.find(".import-target").empty().append(new_namespace + "/" + tr.find(".import-target").data("project_name")) - $.post "#{import_github_url}", {repo_id: id, new_namespace: new_namespace}, dataType: 'script' - - - setInterval (-> - $.get "#{jobs_import_github_path}", (data)-> - $.each data, (i, job) -> - job_item = $("#project_" + job.id) - status_field = job_item.find(".job-status") - - if job.import_status == 'finished' - job_item.removeClass("active").addClass("success") - status_field.html('<span class="cgreen"><i class="fa fa-check"></i> done</span>') - else if job.import_status == 'started' - status_field.html("<i class='fa fa-spinner fa-spin'></i> started") - else - status_field.html(job.import_status) - - ), 4000 + $ -> + new ImporterStatus("#{jobs_import_github_path}", "#{import_github_path}") diff --git a/app/views/import/gitlab/create.js.haml b/app/views/import/gitlab/create.js.haml deleted file mode 100644 index cd4c9fbf360..00000000000 --- a/app/views/import/gitlab/create.js.haml +++ /dev/null @@ -1,18 +0,0 @@ -- if @already_been_taken - :plain - target_field = $("tr#repo_#{@repo_id} .import-target") - origin_target = target_field.text() - project_name = "#{@project_name}" - origin_namespace = "#{@target_namespace}" - target_field.empty() - target_field.append("<p class='alert alert-danger'>This namespace already been taken! Please choose another one</p>") - target_field.append("<input type='text' name='target_namespace' />") - target_field.append("/" + project_name) - target_field.data("project_name", project_name) - target_field.find('input').prop("value", origin_namespace) -- else - :plain - job = $("tr#repo_#{@repo_id}") - job.attr("id", "project_#{@project.id}") - $("table.import-jobs tbody").prepend(job) - job.addClass("active").find(".import-actions").html("<i class='fa fa-spinner fa-spin'></i> started") diff --git a/app/views/import/gitlab/status.html.haml b/app/views/import/gitlab/status.html.haml index ff0ab189c0b..9aedacef04b 100644 --- a/app/views/import/gitlab/status.html.haml +++ b/app/views/import/gitlab/status.html.haml @@ -34,30 +34,6 @@ %td.import-actions.job-status = button_tag "Add", class: "btn btn-add-to-import" - :coffeescript - $(".btn-add-to-import").click () -> - new_namespace = null - tr = $(this).closest("tr") - id = tr.attr("id").replace("repo_", "") - if tr.find(".import-target input").length > 0 - new_namespace = tr.find(".import-target input").prop("value") - tr.find(".import-target").empty().append(new_namespace + "/" + tr.find(".import-target").data("project_name")) - $.post "#{import_gitlab_url}", {repo_id: id, new_namespace: new_namespace}, dataType: 'script' - - - setInterval (-> - $.get "#{jobs_import_gitlab_path}", (data)-> - $.each data, (i, job) -> - job_item = $("#project_" + job.id) - status_field = job_item.find(".job-status") - - if job.import_status == 'finished' - job_item.removeClass("active").addClass("success") - status_field.html('<span class="cgreen"><i class="fa fa-check"></i> done</span>') - else if job.import_status == 'started' - status_field.html("<i class='fa fa-spinner fa-spin'></i> started") - else - status_field.html(job.import_status) - - ), 4000 + $ -> + new ImporterStatus("#{jobs_import_gitlab_path}", "#{import_gitlab_url}") diff --git a/app/views/projects/_github_import_modal.html.haml b/app/views/projects/_github_import_modal.html.haml index 02c9ef45f2b..99325e66119 100644 --- a/app/views/projects/_github_import_modal.html.haml +++ b/app/views/projects/_github_import_modal.html.haml @@ -6,17 +6,4 @@ %h3 GitHub OAuth import .modal-body You need to setup integration with GitHub first. - = link_to 'How to setup integration with GitHub', 'https://gitlab.com/gitlab-org/gitlab-ce/blob/master/doc/integration/github.md' - - -:javascript - $(function(){ - var import_modal = $('#github_import_modal').modal({modal: true, show:false}); - $('.how_to_import_link').bind("click", function(e){ - e.preventDefault(); - import_modal.show(); - }); - $('.modal-header .close').bind("click", function(){ - import_modal.hide(); - }) - }) + = link_to 'How to setup integration with GitHub', 'https://gitlab.com/gitlab-org/gitlab-ce/blob/master/doc/integration/github.md'
\ No newline at end of file diff --git a/app/views/projects/_gitlab_import_modal.html.haml b/app/views/projects/_gitlab_import_modal.html.haml index d402098cbd4..e7503f023b1 100644 --- a/app/views/projects/_gitlab_import_modal.html.haml +++ b/app/views/projects/_gitlab_import_modal.html.haml @@ -6,17 +6,4 @@ %h3 GitLab OAuth import .modal-body You need to setup integration with GitLab first. - = link_to 'How to setup integration with GitLab', 'https://gitlab.com/gitlab-org/gitlab-ce/blob/master/doc/integration/gitlab.md' - - -:javascript - $(function(){ - var import_modal = $('#gitlab_import_modal').modal({modal: true, show:false}); - $('.how_to_import_link').bind("click", function(e){ - e.preventDefault(); - import_modal.show(); - }); - $('.modal-header .close').bind("click", function(){ - import_modal.hide(); - }) - }) + = link_to 'How to setup integration with GitLab', 'https://gitlab.com/gitlab-org/gitlab-ce/blob/master/doc/integration/gitlab.md'
\ No newline at end of file diff --git a/app/views/projects/new.html.haml b/app/views/projects/new.html.haml index 713370e3bfe..61f6a66c386 100644 --- a/app/views/projects/new.html.haml +++ b/app/views/projects/new.html.haml @@ -92,3 +92,11 @@ %i.fa.fa-spinner.fa-spin Creating project & repository. %p Please wait a moment, this page will automatically refresh when ready. + +:coffeescript + $ -> + $('.how_to_import_link').bind 'click', (e) -> + e.preventDefault() + import_modal = $(this).parent().find(".modal").show() + $('.modal-header .close').bind 'click', -> + $(".modal").hide()
\ No newline at end of file diff --git a/app/workers/repository_import_worker.rb b/app/workers/repository_import_worker.rb index 3fb41a528c2..5f9970d3795 100644 --- a/app/workers/repository_import_worker.rb +++ b/app/workers/repository_import_worker.rb @@ -10,13 +10,13 @@ class RepositoryImportWorker project.path_with_namespace, project.import_url) - if project.import_type == 'github' - result_of_data_import = Gitlab::GithubImport::Importer.new(project).execute - elsif project.import_type == 'gitlab' - result_of_data_import = Gitlab::GitlabImport::Importer.new(project).execute - else - result_of_data_import = true - end + result_of_data_import = if project.import_type == 'github' + Gitlab::GithubImport::Importer.new(project).execute + elsif project.import_type == 'gitlab' + Gitlab::GitlabImport::Importer.new(project).execute + else + true + end if result && result_of_data_import project.import_finish diff --git a/lib/gitlab/github_import/importer.rb b/lib/gitlab/github_import/importer.rb index 91a4595b9ea..1f02ee49b6a 100644 --- a/lib/gitlab/github_import/importer.rb +++ b/lib/gitlab/github_import/importer.rb @@ -43,7 +43,8 @@ module Gitlab end def gl_user_id(project, github_id) - user = User.joins(:identities).find_by("identities.extern_uid = ?", github_id.to_s) + user = User.joins(:identities). + find_by("identities.extern_uid = ? AND identities.provider = 'github'", github_id.to_s) (user && user.id) || project.creator_id end end diff --git a/lib/gitlab/gitlab_import/importer.rb b/lib/gitlab/gitlab_import/importer.rb index a529483c1e2..5f9b14399a4 100644 --- a/lib/gitlab/gitlab_import/importer.rb +++ b/lib/gitlab/gitlab_import/importer.rb @@ -42,7 +42,7 @@ module Gitlab private def gl_user_id(project, gitlab_id) - user = User.joins(:identities).find_by("identities.extern_uid = ?", gitlab_id.to_s) + user = User.joins(:identities).find_by("identities.extern_uid = ? AND identities.provider = 'gitlab'", gitlab_id.to_s) (user && user.id) || project.creator_id end end |