Class: Import::GitlabController

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

Instance Method Summary collapse

Instance Method Details

#callbackObject


7
8
9
10
# File 'app/controllers/import/gitlab_controller.rb', line 7

def callback
  session[:gitlab_access_token] = client.get_token(params[:code], callback_import_gitlab_url)
  redirect_to status_import_gitlab_url
end

#createObject


26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/controllers/import/gitlab_controller.rb', line 26

def create
  @repo_id = params[:repo_id].to_i
  repo = client.project(@repo_id)
  @project_name = repo["name"]

  repo_owner = repo["namespace"]["path"]
  repo_owner = current_user.username if repo_owner == client.user["username"]
  @target_namespace = params[:new_namespace].presence || repo_owner

  namespace = get_or_create_namespace || (render and return)

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

#jobsObject


21
22
23
24
# File 'app/controllers/import/gitlab_controller.rb', line 21

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

#statusObject


12
13
14
15
16
17
18
19
# File 'app/controllers/import/gitlab_controller.rb', line 12

def status
  @repos = client.projects

  @already_added_projects = current_user.created_projects.where(import_type: "gitlab")
  already_added_projects_names = @already_added_projects.pluck(:import_source)

  @repos = @repos.to_a.reject{ |repo| already_added_projects_names.include? repo["path_with_namespace"] }
end