2014-12-31 13:07:48 +00:00
|
|
|
module Gitlab
|
2015-02-02 22:26:29 +00:00
|
|
|
module GithubImport
|
2014-12-31 13:07:48 +00:00
|
|
|
class ProjectCreator
|
2015-08-07 07:06:20 +00:00
|
|
|
attr_reader :repo, :namespace, :current_user, :session_data
|
2014-12-31 13:07:48 +00:00
|
|
|
|
2015-08-07 07:06:20 +00:00
|
|
|
def initialize(repo, namespace, current_user, session_data)
|
2014-12-31 13:07:48 +00:00
|
|
|
@repo = repo
|
|
|
|
@namespace = namespace
|
|
|
|
@current_user = current_user
|
2015-08-07 07:06:20 +00:00
|
|
|
@session_data = session_data
|
2014-12-31 13:07:48 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def execute
|
2015-08-07 07:06:20 +00:00
|
|
|
project = ::Projects::CreateService.new(
|
|
|
|
current_user,
|
2014-12-31 13:07:48 +00:00
|
|
|
name: repo.name,
|
|
|
|
path: repo.name,
|
|
|
|
description: repo.description,
|
2015-04-06 12:51:09 +00:00
|
|
|
namespace_id: namespace.id,
|
2014-12-31 13:07:48 +00:00
|
|
|
visibility_level: repo.private ? Gitlab::VisibilityLevel::PRIVATE : Gitlab::VisibilityLevel::PUBLIC,
|
|
|
|
import_type: "github",
|
|
|
|
import_source: repo.full_name,
|
2015-08-07 07:06:20 +00:00
|
|
|
import_url: repo.clone_url.sub("https://", "https://#{@session_data[:github_access_token]}@")
|
2015-04-06 12:51:09 +00:00
|
|
|
).execute
|
2015-08-07 07:06:20 +00:00
|
|
|
|
|
|
|
project.create_import_data(data: { "github_session" => session_data } )
|
|
|
|
project
|
2014-12-31 13:07:48 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|