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

37 lines
1.1 KiB
Ruby
Raw Normal View History

2015-04-26 12:48:37 +05:30
module Gitlab
module GithubImport
class ProjectCreator
2015-09-25 12:07:36 +05:30
attr_reader :repo, :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-09-29 09:46:39 +05:30
project = ::Projects::CreateService.new(
2015-09-25 12:07:36 +05:30
current_user,
2016-09-29 09:46:39 +05:30
name: @name,
path: @name,
2015-04-26 12:48:37 +05:30
description: repo.description,
namespace_id: namespace.id,
2016-09-29 09:46:39 +05:30
visibility_level: repo.private ? Gitlab::VisibilityLevel::PRIVATE : ApplicationSetting.current.default_project_visibility,
2015-04-26 12:48:37 +05:30
import_type: "github",
import_source: repo.full_name,
2016-09-29 09:46:39 +05:30
import_url: repo.clone_url.sub("https://", "https://#{@session_data[:github_access_token]}@")
2015-04-26 12:48:37 +05:30
).execute
2016-09-29 09:46:39 +05:30
# If repo has wiki we'll import it later
if repo.has_wiki? && project
project.project_feature.update_attribute(:wiki_access_level, ProjectFeature::DISABLED)
end
project
2015-04-26 12:48:37 +05:30
end
end
end
end