diff options
author | Douwe Maan <douwe@gitlab.com> | 2015-04-03 16:29:27 +0300 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2015-04-03 16:29:27 +0300 |
commit | 7b5bc32cadbf2c0a3ac1e80643e46786fd8b1b56 (patch) | |
tree | 0dfa9add1156d8ce9ff8709e36da577b7c94ad1c /app/controllers/import | |
parent | 9157985cfce1391973673ea278dc7506a90f8f53 (diff) |
Allow projects to be imported from Google Code.
Diffstat (limited to 'app/controllers/import')
-rw-r--r-- | app/controllers/import/google_code_controller.rb | 63 |
1 files changed, 63 insertions, 0 deletions
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 |