Class: Import::GoogleCodeController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/import/google_code_controller.rb

Instance Method Summary collapse

Instance Method Details

#callbackObject


9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/controllers/import/google_code_controller.rb', line 9

def callback
  dump_file = params[:dump_file]

  unless dump_file.respond_to?(:read)
    return redirect_back_or_default(options: { alert: "You need to upload a Google Takeout archive." })
  end

  begin
    dump = JSON.parse(dump_file.read)
  rescue
    return redirect_back_or_default(options: { alert: "The uploaded file is not a valid Google Takeout archive." })
  end

  client = Gitlab::GoogleCodeImport::Client.new(dump)
  unless client.valid?
    return redirect_back_or_default(options: { alert: "The uploaded file is not a valid Google Takeout archive." })
  end

  session[:google_code_dump] = dump

  if params[:create_user_map] == "1"
    redirect_to new_user_map_import_google_code_path
  else
    redirect_to status_import_google_code_path
  end
end

#createObject


89
90
91
92
93
94
95
96
97
98
99
100
# File 'app/controllers/import/google_code_controller.rb', line 89

def create
  @repo_id = params[:repo_id]
  repo = client.repo(@repo_id)
  @target_namespace = current_user.namespace
  @project_name = repo.name

  namespace = @target_namespace

  user_map = session[:google_code_user_map]

  @project = Gitlab::GoogleCodeImport::ProjectCreator.new(repo, namespace, current_user, user_map).execute
end

#create_user_mapObject


40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'app/controllers/import/google_code_controller.rb', line 40

def create_user_map
  user_map_json = params[:user_map]
  user_map_json = "{}" if user_map_json.blank?

  begin
    user_map = JSON.parse(user_map_json)
  rescue
    flash.now[:alert] = "The entered user map is not a valid JSON user map."

    render "new_user_map" and return
  end

  unless user_map.is_a?(Hash) && user_map.all? { |k, v| k.is_a?(String) && v.is_a?(String) }
    flash.now[:alert] = "The entered user map is not a valid JSON user map."

    render "new_user_map" and return
  end

  # This is the default, so let's not save it into the database.
  user_map.reject! do |key, value|
    value == Gitlab::GoogleCodeImport::Client.mask_email(key)
  end

  session[:google_code_user_map] = user_map

  flash[:notice] = "The user map has been saved. Continue by selecting the projects you want to import."

  redirect_to status_import_google_code_path
end

#jobsObject


84
85
86
87
# File 'app/controllers/import/google_code_controller.rb', line 84

def jobs
  jobs = current_user.created_projects.where(import_type: "google_code").to_json(only: [:id, :import_status])
  render json: jobs
end

#newObject


5
6
7
# File 'app/controllers/import/google_code_controller.rb', line 5

def new

end

#new_user_mapObject


36
37
38
# File 'app/controllers/import/google_code_controller.rb', line 36

def new_user_map

end

#statusObject


70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'app/controllers/import/google_code_controller.rb', line 70

def status
  unless client.valid?
    return redirect_to new_import_google_code_path
  end

  @repos = client.repos
  @incompatible_repos = client.incompatible_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