BigW Consortium Gitlab

project_creator.rb 987 Bytes
Newer Older
Valery Sizov committed
1
module Gitlab
2
  module GithubImport
Valery Sizov committed
3
    class ProjectCreator
4
      attr_reader :repo, :namespace, :current_user, :session_data
Valery Sizov committed
5

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

      def execute
14 15
        project = ::Projects::CreateService.new(
          current_user,
Valery Sizov committed
16 17 18
          name: repo.name,
          path: repo.name,
          description: repo.description,
19
          namespace_id: namespace.id,
Valery Sizov committed
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.sub("https://", "https://#{@session_data[:github_access_token]}@")
24
        ).execute
25 26 27

        project.create_import_data(data: { "github_session" => session_data } )
        project
Valery Sizov committed
28 29 30 31
      end
    end
  end
end