project_creator.rb 859 Bytes
Newer Older
Douwe Maan's avatar
Douwe Maan committed
1 2 3
module Gitlab
  module BitbucketImport
    class ProjectCreator
4
      attr_reader :repo, :name, :namespace, :current_user, :session_data
Douwe Maan's avatar
Douwe Maan committed
5

6
      def initialize(repo, name, namespace, current_user, session_data)
Douwe Maan's avatar
Douwe Maan committed
7
        @repo = repo
8
        @name = name
Douwe Maan's avatar
Douwe Maan committed
9 10
        @namespace = namespace
        @current_user = current_user
11
        @session_data = session_data
Douwe Maan's avatar
Douwe Maan committed
12 13 14
      end

      def execute
15
        ::Projects::CreateService.new(
Gabriel Mazetto's avatar
Gabriel Mazetto committed
16
          current_user,
17 18
          name: name,
          path: name,
19
          description: repo.description,
20
          namespace_id: namespace.id,
21 22 23
          visibility_level: repo.visibility_level,
          import_type: 'bitbucket',
          import_source: repo.full_name,
24
          import_url: repo.clone_url(session_data[:token]),
25
          import_data: { credentials: session_data }
26
        ).execute
Douwe Maan's avatar
Douwe Maan committed
27 28 29 30
      end
    end
  end
end