BigW Consortium Gitlab

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

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

      def execute
14 15
        project = ::Projects::CreateService.new(
          current_user,
Douwe Maan committed
16 17 18
          name: repo["name"],
          path: repo["slug"],
          description: repo["description"],
19
          namespace_id: namespace.id,
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
        project.create_or_update_import_data(credentials: { bb_session: session_data })
27

28
        project
Douwe Maan committed
29 30 31 32
      end
    end
  end
end