2018-11-17 00:37:17 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2014-12-31 13:07:48 +00:00
|
|
|
module Gitlab
|
2017-10-13 16:50:36 +00:00
|
|
|
module LegacyGithubImport
|
2014-12-31 13:07:48 +00:00
|
|
|
class ProjectCreator
|
2016-10-17 15:58:57 +00:00
|
|
|
attr_reader :repo, :name, :namespace, :current_user, :session_data, :type
|
2014-12-31 13:07:48 +00:00
|
|
|
|
2016-10-17 15:58:57 +00:00
|
|
|
def initialize(repo, name, namespace, current_user, session_data, type: 'github')
|
2014-12-31 13:07:48 +00:00
|
|
|
@repo = repo
|
2016-08-08 13:05:58 +00:00
|
|
|
@name = name
|
2014-12-31 13:07:48 +00:00
|
|
|
@namespace = namespace
|
|
|
|
@current_user = current_user
|
2015-08-07 07:06:20 +00:00
|
|
|
@session_data = session_data
|
2016-10-17 15:58:57 +00:00
|
|
|
@type = type
|
2014-12-31 13:07:48 +00:00
|
|
|
end
|
|
|
|
|
2018-03-07 15:58:50 +00:00
|
|
|
def execute(extra_attrs = {})
|
|
|
|
attrs = {
|
2016-10-04 05:40:03 +00:00
|
|
|
name: name,
|
|
|
|
path: name,
|
2014-12-31 13:07:48 +00:00
|
|
|
description: repo.description,
|
2015-04-06 12:51:09 +00:00
|
|
|
namespace_id: namespace.id,
|
2016-10-04 05:40:03 +00:00
|
|
|
visibility_level: visibility_level,
|
2016-10-17 15:58:57 +00:00
|
|
|
import_type: type,
|
2014-12-31 13:07:48 +00:00
|
|
|
import_source: repo.full_name,
|
2016-10-04 05:40:03 +00:00
|
|
|
import_url: import_url,
|
|
|
|
skip_wiki: skip_wiki
|
2018-03-07 15:58:50 +00:00
|
|
|
}.merge!(extra_attrs)
|
|
|
|
|
|
|
|
::Projects::CreateService.new(current_user, attrs).execute
|
2016-10-04 05:40:03 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
2016-08-01 22:31:21 +00:00
|
|
|
|
2016-10-04 05:40:03 +00:00
|
|
|
def import_url
|
2016-10-17 15:58:57 +00:00
|
|
|
repo.clone_url.sub('://', "://#{session_data[:github_access_token]}@")
|
2016-10-04 05:40:03 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def visibility_level
|
2019-04-08 14:12:39 +00:00
|
|
|
visibility_level = repo.private ? Gitlab::VisibilityLevel::PRIVATE : @namespace.visibility_level
|
2018-06-05 20:20:37 +00:00
|
|
|
visibility_level = Gitlab::CurrentSettings.default_project_visibility if Gitlab::CurrentSettings.restricted_visibility_levels.include?(visibility_level)
|
|
|
|
|
|
|
|
visibility_level
|
2016-10-04 05:40:03 +00:00
|
|
|
end
|
2016-08-01 22:31:21 +00:00
|
|
|
|
2016-10-04 05:40:03 +00: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 11:21:53 +00:00
|
|
|
end
|
2014-12-31 13:07:48 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|