Class: Gitlab::BitbucketImport::ProjectCreator

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/bitbucket_import/project_creator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(repo, namespace, current_user, session_data) ⇒ ProjectCreator


6
7
8
9
10
11
# File 'lib/gitlab/bitbucket_import/project_creator.rb', line 6

def initialize(repo, namespace, current_user, session_data)
  @repo = repo
  @namespace = namespace
  @current_user = current_user
  @session_data = session_data
end

Instance Attribute Details

#current_userObject (readonly)

Returns the value of attribute current_user


4
5
6
# File 'lib/gitlab/bitbucket_import/project_creator.rb', line 4

def current_user
  @current_user
end

#namespaceObject (readonly)

Returns the value of attribute namespace


4
5
6
# File 'lib/gitlab/bitbucket_import/project_creator.rb', line 4

def namespace
  @namespace
end

#repoObject (readonly)

Returns the value of attribute repo


4
5
6
# File 'lib/gitlab/bitbucket_import/project_creator.rb', line 4

def repo
  @repo
end

#session_dataObject (readonly)

Returns the value of attribute session_data


4
5
6
# File 'lib/gitlab/bitbucket_import/project_creator.rb', line 4

def session_data
  @session_data
end

Instance Method Details

#executeObject


13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/gitlab/bitbucket_import/project_creator.rb', line 13

def execute
  project = ::Projects::CreateService.new(
    current_user,
    name: repo["name"],
    path: repo["slug"],
    description: repo["description"],
    namespace_id: namespace.id,
    visibility_level: repo["is_private"] ? Gitlab::VisibilityLevel::PRIVATE : Gitlab::VisibilityLevel::PUBLIC,
    import_type: "bitbucket",
    import_source: "#{repo["owner"]}/#{repo["slug"]}",
    import_url: "ssh://[email protected]/#{repo["owner"]}/#{repo["slug"]}.git",
  ).execute

  project.create_or_update_import_data(credentials: { bb_session: session_data })

  project
end