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

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

      def execute
Gabriel Mazetto's avatar
Gabriel Mazetto committed
14 15
        project = ::Projects::CreateService.new(
          current_user,
Douwe Maan's avatar
Douwe Maan committed
16 17 18
          name: repo["name"],
          path: repo["slug"],
          description: repo["description"],
19
          namespace_id: namespace.id,
Douwe Maan's avatar
Douwe Maan committed
20 21 22
          visibility_level: repo["is_private"] ? Gitlab::VisibilityLevel::PRIVATE : Gitlab::VisibilityLevel::PUBLIC,
          import_type: "bitbucket",
          import_source: "#{repo["owner"]}/#{repo["slug"]}",
23
          import_url: "ssh://git@bitbucket.org/#{repo["owner"]}/#{repo["slug"]}.git",
24
        ).execute
25

26 27
        import_data = project.import_data
        import_data.credentials.merge!("bb_session" => session_data)
28 29
        import_data.save

30
        project
Douwe Maan's avatar
Douwe Maan committed
31 32 33 34
      end
    end
  end
end