debian-mirror-gitlab/lib/gitlab/github_import/project_creator.rb

50 lines
1.3 KiB
Ruby
Raw Normal View History

2015-04-26 12:48:37 +05:30
module Gitlab
module GithubImport
class ProjectCreator
2016-11-03 12:29:30 +05:30
attr_reader :repo, :name, :namespace, :current_user, :session_data
2015-04-26 12:48:37 +05:30
2016-09-29 09:46:39 +05:30
def initialize(repo, name, namespace, current_user, session_data)
2015-04-26 12:48:37 +05:30
@repo = repo
2016-09-29 09:46:39 +05:30
@name = name
2015-04-26 12:48:37 +05:30
@namespace = namespace
@current_user = current_user
2015-09-25 12:07:36 +05:30
@session_data = session_data
2015-04-26 12:48:37 +05:30
end
def execute
2016-11-03 12:29:30 +05:30
::Projects::CreateService.new(
2015-09-25 12:07:36 +05:30
current_user,
2016-11-03 12:29:30 +05:30
name: name,
path: name,
2015-04-26 12:48:37 +05:30
description: repo.description,
namespace_id: namespace.id,
2016-11-03 12:29:30 +05:30
visibility_level: visibility_level,
2015-04-26 12:48:37 +05:30
import_type: "github",
import_source: repo.full_name,
2016-11-03 12:29:30 +05:30
import_url: import_url,
skip_wiki: skip_wiki
2015-04-26 12:48:37 +05:30
).execute
2016-11-03 12:29:30 +05:30
end
private
2016-09-29 09:46:39 +05:30
2016-11-03 12:29:30 +05:30
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-09-29 09:46:39 +05:30
2016-11-03 12:29:30 +05:30
#
# 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?
2015-04-26 12:48:37 +05:30
end
end
end
end