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

50 lines
1.3 KiB
Ruby
Raw Normal View History

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
attr_reader :repo, :name, :namespace, :current_user, :session_data
2014-12-31 08:07:48 -05:00
def initialize(repo, name, namespace, current_user, session_data)
2014-12-31 08:07:48 -05:00
@repo = repo
@name = name
2014-12-31 08:07:48 -05:00
@namespace = namespace
@current_user = current_user
@session_data = session_data
2014-12-31 08:07:48 -05:00
end
def execute
::Projects::CreateService.new(
current_user,
name: name,
path: name,
2014-12-31 08:07:48 -05:00
description: repo.description,
namespace_id: namespace.id,
visibility_level: visibility_level,
2014-12-31 08:07:48 -05:00
import_type: "github",
import_source: repo.full_name,
import_url: import_url,
skip_wiki: skip_wiki
).execute
end
private
2016-08-01 18:31:21 -04:00
def import_url
repo.clone_url.sub('https://', "https://#{session_data[:github_access_token]}@")
end
def visibility_level
repo.private ? Gitlab::VisibilityLevel::PRIVATE : ApplicationSetting.current.default_project_visibility
end
2016-08-01 18:31:21 -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?
end
2014-12-31 08:07:48 -05:00
end
end
end