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
path: root/app
diff options
context:
space:
mode:
authorDouwe Maan <douwe@gitlab.com>2015-04-03 16:29:27 +0300
committerDouwe Maan <douwe@gitlab.com>2015-04-03 16:29:27 +0300
commit7b5bc32cadbf2c0a3ac1e80643e46786fd8b1b56 (patch)
tree0dfa9add1156d8ce9ff8709e36da577b7c94ad1c /app
parent9157985cfce1391973673ea278dc7506a90f8f53 (diff)
Allow projects to be imported from Google Code.
Diffstat (limited to 'app')
-rw-r--r--app/assets/stylesheets/base/mixins.scss16
-rw-r--r--app/assets/stylesheets/pages/notes.scss16
-rw-r--r--app/controllers/import/google_code_controller.rb63
-rw-r--r--app/models/project.rb9
-rw-r--r--app/views/import/google_code/new.html.haml17
-rw-r--r--app/views/import/google_code/status.html.haml45
-rw-r--r--app/views/projects/new.html.haml4
-rw-r--r--app/workers/repository_import_worker.rb2
8 files changed, 158 insertions, 14 deletions
diff --git a/app/assets/stylesheets/base/mixins.scss b/app/assets/stylesheets/base/mixins.scss
index ccba65e3fd5..216f25cdcd5 100644
--- a/app/assets/stylesheets/base/mixins.scss
+++ b/app/assets/stylesheets/base/mixins.scss
@@ -119,6 +119,22 @@
li {
line-height: 1.5;
}
+
+ a[href*="/uploads/"], a[href*="storage.googleapis.com/google-code-attachments/"] {
+ &:before {
+ margin-right: 4px;
+
+ font: normal normal normal 14px/1 FontAwesome;
+ font-size: inherit;
+ text-rendering: auto;
+ -webkit-font-smoothing: antialiased;
+ content: "\f0c6";
+ }
+
+ &:hover:before {
+ text-decoration: none;
+ }
+ }
}
@mixin str-truncated($max_width: 82%) {
diff --git a/app/assets/stylesheets/pages/notes.scss b/app/assets/stylesheets/pages/notes.scss
index d66093bc2e5..facd7e19314 100644
--- a/app/assets/stylesheets/pages/notes.scss
+++ b/app/assets/stylesheets/pages/notes.scss
@@ -62,20 +62,8 @@ ul.notes {
word-wrap: break-word;
@include md-typography;
- a[href*="/uploads/"] {
- &:before {
- margin-right: 4px;
-
- font: normal normal normal 14px/1 FontAwesome;
- font-size: inherit;
- text-rendering: auto;
- -webkit-font-smoothing: antialiased;
- content: "\f0c6";
- }
-
- &:hover:before {
- text-decoration: none;
- }
+ hr {
+ margin: 10px 0;
}
}
}
diff --git a/app/controllers/import/google_code_controller.rb b/app/controllers/import/google_code_controller.rb
new file mode 100644
index 00000000000..9542a33193a
--- /dev/null
+++ b/app/controllers/import/google_code_controller.rb
@@ -0,0 +1,63 @@
+class Import::GoogleCodeController < Import::BaseController
+
+ def new
+
+ end
+
+ def callback
+ dump_file = params[:dump_file]
+
+ unless dump_file.respond_to?(:read)
+ return redirect_to :back, alert: "You need to upload a Google Takeout JSON file."
+ end
+
+ begin
+ dump = JSON.parse(dump_file.read)
+ rescue
+ return redirect_to :back, alert: "The uploaded file is not a valid Google Takeout JSON file."
+ end
+
+ unless Gitlab::GoogleCodeImport::Client.new(dump).valid?
+ return redirect_to :back, alert: "The uploaded file is not a valid Google Takeout JSON file."
+ end
+
+ session[:google_code_dump] = dump
+ redirect_to status_import_google_code_path
+ end
+
+ def status
+ unless client.valid?
+ return redirect_to new_import_google_path
+ end
+
+ @repos = client.repos
+
+ @already_added_projects = current_user.created_projects.where(import_type: "google_code")
+ already_added_projects_names = @already_added_projects.pluck(:import_source)
+
+ @repos.reject! { |repo| already_added_projects_names.include? repo.name }
+ end
+
+ def jobs
+ jobs = current_user.created_projects.where(import_type: "google_code").to_json(only: [:id, :import_status])
+ render json: jobs
+ end
+
+ def create
+ @repo_id = params[:repo_id]
+ repo = client.repo(@repo_id)
+ @target_namespace = current_user.namespace
+ @project_name = repo.name
+
+ namespace = @target_namespace
+
+ @project = Gitlab::GoogleCodeImport::ProjectCreator.new(repo, namespace, current_user).execute
+ end
+
+ private
+
+ def client
+ @client ||= Gitlab::GoogleCodeImport::Client.new(session[:google_code_dump])
+ end
+
+end
diff --git a/app/models/project.rb b/app/models/project.rb
index 79572f255db..9b0d5c509b4 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -27,6 +27,7 @@
# import_type :string(255)
# import_source :string(255)
# avatar :string(255)
+# import_data :text
#
require 'carrierwave/orm/activerecord'
@@ -50,6 +51,8 @@ class Project < ActiveRecord::Base
default_value_for :wall_enabled, false
default_value_for :snippets_enabled, gitlab_config_features.snippets
+ serialize :import_data, JSON
+
# set last_activity_at to the same as created_at
after_create :set_last_activity_at
def set_last_activity_at
@@ -185,6 +188,7 @@ class Project < ActiveRecord::Base
state :failed
after_transition any => :started, do: :add_import_job
+ after_transition any => :finished, do: :clear_import_data
end
class << self
@@ -262,6 +266,11 @@ class Project < ActiveRecord::Base
RepositoryImportWorker.perform_in(2.seconds, id)
end
+ def clear_import_data
+ self.import_data = nil
+ self.save
+ end
+
def import?
import_url.present?
end
diff --git a/app/views/import/google_code/new.html.haml b/app/views/import/google_code/new.html.haml
new file mode 100644
index 00000000000..8df5b5d31f4
--- /dev/null
+++ b/app/views/import/google_code/new.html.haml
@@ -0,0 +1,17 @@
+%h3.page-title
+ %i.fa.fa-google
+ Import projects from Google Code
+%hr
+
+= form_tag callback_import_google_code_path, class: 'form-horizontal', multipart: true do
+ %ul
+ %li
+ Use Google Takeout etc
+
+ .form-group
+ = label_tag :dump_file, "Google Takeout JSON file", class: 'control-label'
+ .col-sm-10
+ %input{type: "file", name: "dump_file", id: "dump_file"}
+
+ .form-actions
+ = submit_tag 'Select projects to import', class: "btn btn-create"
diff --git a/app/views/import/google_code/status.html.haml b/app/views/import/google_code/status.html.haml
new file mode 100644
index 00000000000..eba9c5296bc
--- /dev/null
+++ b/app/views/import/google_code/status.html.haml
@@ -0,0 +1,45 @@
+%h3.page-title
+ %i.fa.fa-google
+ Import projects from Google Code
+
+%p.light
+ Select projects you want to import.
+%hr
+%p
+ = button_tag 'Import all projects', class: "btn btn-success js-import-all"
+
+%table.table.import-jobs
+ %thead
+ %tr
+ %th From Google Code
+ %th To GitLab
+ %th Status
+ %tbody
+ - @already_added_projects.each do |project|
+ %tr{id: "project_#{project.id}", class: "#{project_status_css_class(project.import_status)}"}
+ %td
+ = link_to project.import_source, "https://code.google.com/p/#{project.import_source}", target: "_blank"
+ %td
+ %strong= link_to project.path_with_namespace, [project.namespace.becomes(Namespace), project]
+ %td.job-status
+ - if project.import_status == 'finished'
+ %span
+ %i.fa.fa-check
+ done
+ - elsif project.import_status == 'started'
+ %i.fa.fa-spinner.fa-spin
+ started
+ - else
+ = project.human_import_status_name
+
+ - @repos.each do |repo|
+ %tr{id: "repo_#{repo.id}"}
+ %td
+ = link_to repo.name, "https://code.google.com/p/#{repo.name}", target: "_blank"
+ %td.import-target
+ = "#{current_user.username}/#{repo.name}"
+ %td.import-actions.job-status
+ = button_tag "Import", class: "btn js-add-to-import"
+
+:coffeescript
+ new ImporterStatus("#{jobs_import_google_code_path}", "#{import_google_code_path}")
diff --git a/app/views/projects/new.html.haml b/app/views/projects/new.html.haml
index 69909a8554e..a06c85b4251 100644
--- a/app/views/projects/new.html.haml
+++ b/app/views/projects/new.html.haml
@@ -62,6 +62,10 @@
%i.icon-gitorious.icon-gitorious-small
Gitorious.org
+ = link_to new_import_google_code_path, class: 'btn' do
+ %i.fa.fa-google
+ Google Code
+
= link_to "#", class: 'btn js-toggle-button' do
%i.fa.fa-git
%span Any repo by URL
diff --git a/app/workers/repository_import_worker.rb b/app/workers/repository_import_worker.rb
index 437640d2305..e6a50afedb1 100644
--- a/app/workers/repository_import_worker.rb
+++ b/app/workers/repository_import_worker.rb
@@ -18,6 +18,8 @@ class RepositoryImportWorker
Gitlab::GitlabImport::Importer.new(project).execute
elsif project.import_type == 'bitbucket'
Gitlab::BitbucketImport::Importer.new(project).execute
+ elsif project.import_type == 'google_code'
+ Gitlab::GoogleCodeImport::Importer.new(project).execute
else
true
end