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

57 lines
1.6 KiB
Ruby
Raw Normal View History

2019-02-15 15:39:39 +05:30
# frozen_string_literal: true
2015-04-26 12:48:37 +05:30
module Gitlab
2018-03-17 18:26:18 +05:30
module LegacyGithubImport
2015-04-26 12:48:37 +05:30
class ProjectCreator
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
2018-03-27 19:54:05 +05:30
def execute(extra_attrs = {})
attrs = {
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
2018-03-27 19:54:05 +05:30
}.merge!(extra_attrs)
::Projects::CreateService.new(current_user, attrs).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
2019-07-31 22:56:46 +05:30
visibility_level = repo.private ? Gitlab::VisibilityLevel::PRIVATE : @namespace.visibility_level
2018-11-08 19:23:39 +05:30
visibility_level = Gitlab::CurrentSettings.default_project_visibility if Gitlab::CurrentSettings.restricted_visibility_levels.include?(visibility_level)
visibility_level
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