gitlab-org--gitlab-foss/lib/gitlab/bitbucket_import/project_creator.rb

36 lines
1.1 KiB
Ruby
Raw Normal View History

2015-02-17 10:59:50 -05:00
module Gitlab
module BitbucketImport
class ProjectCreator
attr_reader :repo, :namespace, :current_user, :session_data
2015-02-17 10:59:50 -05: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
@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"],
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"]}",
import_url: "ssh://git@bitbucket.org/#{repo["owner"]}/#{repo["slug"]}.git",
).execute
2016-03-22 12:53:53 -04:00
import_data = project.import_data
# merge! with a bang doesn't work here
import_data.credentials = import_data.credentials.merge("bb_session" => session_data)
import_data.save
project
2015-02-17 10:59:50 -05:00
end
end
end
end