This instance will be upgraded to Heptapod 0.31.0rc on 2022-05-19 at 11:00 UTC+2 (a few minutes of down time)

project_creator.rb 1.02 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
        import_data = project.import_data
        import_data.credentials.merge!("bb_session" => session_data)
27
        project
Douwe Maan's avatar
Douwe Maan committed
28
29
30
31
      end
    end
  end
end