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

53 lines
1.4 KiB
Ruby
Raw Normal View History

2015-04-26 12:48:37 +05:30
module Gitlab
module GithubImport
class ProjectCreator
2017-08-17 22:00:37 +05:30
include Gitlab::CurrentSettings
2015-04-26 12:48:37 +05:30
2017-08-17 22:00:37 +05:30
attr_reader :repo, :name, :namespace, :current_user, :session_data, :type
def initialize(repo, name, namespace, current_user, session_data, type: 'github')
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
2017-08-17 22:00:37 +05:30
@type = type
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,
2017-08-17 22:00:37 +05:30
import_type: type,
2015-04-26 12:48:37 +05:30
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
2017-08-17 22:00:37 +05:30
repo.clone_url.sub('://', "://#{session_data[:github_access_token]}@")
2016-11-03 12:29:30 +05:30
end
def visibility_level
2017-08-17 22:00:37 +05:30
repo.private ? Gitlab::VisibilityLevel::PRIVATE : current_application_settings.default_project_visibility
2016-11-03 12:29:30 +05:30
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