2014-12-31 08:07:48 -05:00
|
|
|
module Gitlab
|
2015-02-02 17:26:29 -05:00
|
|
|
module GithubImport
|
2014-12-31 08:07:48 -05:00
|
|
|
class ProjectCreator
|
2017-01-21 19:11:19 -05:00
|
|
|
include Gitlab::CurrentSettings
|
|
|
|
|
2016-10-17 11:58:57 -04:00
|
|
|
attr_reader :repo, :name, :namespace, :current_user, :session_data, :type
|
2014-12-31 08:07:48 -05:00
|
|
|
|
2016-10-17 11:58:57 -04:00
|
|
|
def initialize(repo, name, namespace, current_user, session_data, type: 'github')
|
2014-12-31 08:07:48 -05:00
|
|
|
@repo = repo
|
2016-08-08 09:05:58 -04:00
|
|
|
@name = name
|
2014-12-31 08:07:48 -05:00
|
|
|
@namespace = namespace
|
|
|
|
@current_user = current_user
|
2015-08-07 03:06:20 -04:00
|
|
|
@session_data = session_data
|
2016-10-17 11:58:57 -04:00
|
|
|
@type = type
|
2014-12-31 08:07:48 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def execute
|
2016-10-04 01:40:03 -04:00
|
|
|
::Projects::CreateService.new(
|
2015-08-07 03:06:20 -04:00
|
|
|
current_user,
|
2016-10-04 01:40:03 -04:00
|
|
|
name: name,
|
|
|
|
path: name,
|
2014-12-31 08:07:48 -05:00
|
|
|
description: repo.description,
|
2015-04-06 08:51:09 -04:00
|
|
|
namespace_id: namespace.id,
|
2016-10-04 01:40:03 -04:00
|
|
|
visibility_level: visibility_level,
|
2016-10-17 11:58:57 -04:00
|
|
|
import_type: type,
|
2014-12-31 08:07:48 -05:00
|
|
|
import_source: repo.full_name,
|
2016-10-04 01:40:03 -04:00
|
|
|
import_url: import_url,
|
|
|
|
skip_wiki: skip_wiki
|
2015-04-06 08:51:09 -04:00
|
|
|
).execute
|
2016-10-04 01:40:03 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
2016-08-01 18:31:21 -04:00
|
|
|
|
2016-10-04 01:40:03 -04:00
|
|
|
def import_url
|
2016-10-17 11:58:57 -04:00
|
|
|
repo.clone_url.sub('://', "://#{session_data[:github_access_token]}@")
|
2016-10-04 01:40:03 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def visibility_level
|
2017-01-21 19:11:19 -05:00
|
|
|
repo.private ? Gitlab::VisibilityLevel::PRIVATE : current_application_settings.default_project_visibility
|
2016-10-04 01:40:03 -04:00
|
|
|
end
|
2016-08-01 18:31:21 -04:00
|
|
|
|
2016-10-04 01:40:03 -04:00
|
|
|
#
|
|
|
|
# If the GitHub project repository has wiki, we should not create the
|
|
|
|
# default wiki. Otherwise the GitHub importer will fail because the wiki
|
|
|
|
# repository already exist.
|
|
|
|
#
|
|
|
|
def skip_wiki
|
|
|
|
repo.has_wiki?
|
2016-03-04 06:21:53 -05:00
|
|
|
end
|
2014-12-31 08:07:48 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|