Class: Import::BitbucketController

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

Instance Method Summary collapse

Instance Method Details

#callbackObject


8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'app/controllers/import/bitbucket_controller.rb', line 8

def callback
  request_token = session.delete(:oauth_request_token)
  raise "Session expired!" if request_token.nil?

  request_token.symbolize_keys!

  access_token = client.get_token(request_token, params[:oauth_verifier], callback_import_bitbucket_url)

  session[:bitbucket_access_token] = access_token.token
  session[:bitbucket_access_token_secret] = access_token.secret

  redirect_to status_import_bitbucket_url
end

#createObject


37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'app/controllers/import/bitbucket_controller.rb', line 37

def create
  @repo_id = params[:repo_id] || ""
  repo = client.project(@repo_id.gsub("___", "/"))
  @project_name = repo["slug"]

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

  namespace = get_or_create_namespace || (render and return)

  unless Gitlab::BitbucketImport::KeyAdder.new(repo, current_user, access_params).execute
    @access_denied = true
    render
    return
  end

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

#jobsObject


32
33
34
35
# File 'app/controllers/import/bitbucket_controller.rb', line 32

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

#statusObject


22
23
24
25
26
27
28
29
30
# File 'app/controllers/import/bitbucket_controller.rb', line 22

def status
  @repos = client.projects
  @incompatible_repos = client.incompatible_projects

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

  @repos.to_a.reject!{ |repo| already_added_projects_names.include? "#{repo["owner"]}/#{repo["slug"]}" }
end