Class: Import::FogbugzController

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

Instance Method Summary collapse

Instance Method Details

#callbackObject


11
12
13
14
15
16
17
18
19
20
21
22
# File 'app/controllers/import/fogbugz_controller.rb', line 11

def callback
  begin
    res = Gitlab::FogbugzImport::Client.new(import_params.symbolize_keys)
  rescue
    # If the URI is invalid various errors can occur
    return redirect_to new_import_fogbugz_path, alert: 'Could not connect to FogBugz, check your URL'
  end
  session[:fogbugz_token] = res.get_token
  session[:fogbugz_uri] = params[:uri]

  redirect_to new_user_map_import_fogbugz_path
end

#createObject


62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'app/controllers/import/fogbugz_controller.rb', line 62

def create
  @repo_id = params[:repo_id]
  repo = client.repo(@repo_id)
  fb_session = { uri: session[:fogbugz_uri], token: session[:fogbugz_token] }
  @target_namespace = current_user.namespace
  @project_name = repo.name

  namespace = @target_namespace

  umap = session[:fogbugz_user_map] || client.user_map

  @project = Gitlab::FogbugzImport::ProjectCreator.new(repo, fb_session, namespace, current_user, umap).execute
end

#create_user_mapObject


28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'app/controllers/import/fogbugz_controller.rb', line 28

def create_user_map
  user_map = params[:users]

  unless user_map.is_a?(Hash) && user_map.all? { |k, v| !v[:name].blank? }
    flash.now[:alert] = 'All users must have a name.'

    render 'new_user_map' and return
  end

  session[:fogbugz_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_fogbugz_path
end

#jobsObject


57
58
59
60
# File 'app/controllers/import/fogbugz_controller.rb', line 57

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

#newObject


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

def new

end

#new_user_mapObject


24
25
26
# File 'app/controllers/import/fogbugz_controller.rb', line 24

def new_user_map

end

#statusObject


44
45
46
47
48
49
50
51
52
53
54
55
# File 'app/controllers/import/fogbugz_controller.rb', line 44

def status
  unless client.valid?
    return redirect_to new_import_fogbugz_path
  end

  @repos = client.repos

  @already_added_projects = current_user.created_projects.where(import_type: 'fogbugz')
  already_added_projects_names = @already_added_projects.pluck(:import_source)

  @repos.reject! { |repo| already_added_projects_names.include? repo.name }
end