project_creator.rb 1.15 KB
Newer Older
1
2
3
module Gitlab
  module GithubImport
    class ProjectCreator
4
      attr_reader :repo, :namespace, :current_user, :session_data
5

6
      def initialize(repo, namespace, current_user, session_data)
7
8
9
        @repo = repo
        @namespace = namespace
        @current_user = current_user
10
        @session_data = session_data
11
12
13
      end

      def execute
14
15
        project = ::Projects::CreateService.new(
          current_user,
16
17
18
          name: repo.name,
          path: repo.name,
          description: repo.description,
19
          namespace_id: namespace.id,
20
21
22
          visibility_level: repo.private ? Gitlab::VisibilityLevel::PRIVATE : Gitlab::VisibilityLevel::PUBLIC,
          import_type: "github",
          import_source: repo.full_name,
23
          import_url: repo.clone_url,
24
          wiki_enabled: !repo.has_wiki? # If repo has wiki we'll import it later
25
        ).execute
26

27
        create_import_data(project)
28
        project
29
      end
30
31
32
33
34
35
36
37

      private

      def create_import_data(project)
        project.create_import_data(
          credentials: session_data.delete(:github_access_token),
          data: { "github_session" => session_data })
      end
38
39
40
    end
  end
end