2015-02-17 10:59:50 -05:00
|
|
|
module Gitlab
|
|
|
|
module BitbucketImport
|
|
|
|
class ProjectCreator
|
2015-08-07 03:06:20 -04:00
|
|
|
attr_reader :repo, :namespace, :current_user, :session_data
|
2015-02-17 10:59:50 -05:00
|
|
|
|
2015-08-07 03:06:20 -04:00
|
|
|
def initialize(repo, namespace, current_user, session_data)
|
2015-02-17 10:59:50 -05:00
|
|
|
@repo = repo
|
|
|
|
@namespace = namespace
|
|
|
|
@current_user = current_user
|
2015-08-07 03:06:20 -04:00
|
|
|
@session_data = session_data
|
2015-02-17 10:59:50 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def execute
|
2015-12-14 21:53:52 -05:00
|
|
|
project = ::Projects::CreateService.new(
|
|
|
|
current_user,
|
2015-02-17 10:59:50 -05:00
|
|
|
name: repo["name"],
|
|
|
|
path: repo["slug"],
|
|
|
|
description: repo["description"],
|
2015-04-06 08:51:09 -04:00
|
|
|
namespace_id: namespace.id,
|
2015-02-17 10:59:50 -05:00
|
|
|
visibility_level: repo["is_private"] ? Gitlab::VisibilityLevel::PRIVATE : Gitlab::VisibilityLevel::PUBLIC,
|
|
|
|
import_type: "bitbucket",
|
|
|
|
import_source: "#{repo["owner"]}/#{repo["slug"]}",
|
2015-08-07 03:06:20 -04:00
|
|
|
import_url: "ssh://git@bitbucket.org/#{repo["owner"]}/#{repo["slug"]}.git",
|
2015-04-06 08:51:09 -04:00
|
|
|
).execute
|
2016-03-29 10:10:35 -04:00
|
|
|
|
2016-03-22 12:53:53 -04:00
|
|
|
import_data = project.import_data
|
2016-03-29 12:43:23 -04:00
|
|
|
# merge! with a bang doesn't work here
|
|
|
|
import_data.credentials = import_data.credentials.merge("bb_session" => session_data)
|
2016-03-29 10:10:35 -04:00
|
|
|
import_data.save
|
|
|
|
|
2015-08-07 03:06:20 -04:00
|
|
|
project
|
2015-02-17 10:59:50 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|