BigW Consortium Gitlab

project_creator.rb 959 Bytes
Newer Older
1 2 3
module Gitlab
  module GitlabImport
    class ProjectCreator
4
      attr_reader :repo, :namespace, :current_user, :session_data
5

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

      def execute
14 15
        project = ::Projects::CreateService.new(
          current_user,
16 17 18
          name: repo["name"],
          path: repo["path"],
          description: repo["description"],
19
          namespace_id: namespace.id,
20 21 22
          visibility_level: repo["visibility_level"],
          import_type: "gitlab",
          import_source: repo["path_with_namespace"],
23
          import_url: repo["http_url_to_repo"].sub("://", "://oauth2:#{@session_data[:gitlab_access_token]}@")
24
        ).execute
25 26 27

        project.create_import_data(data: { "gitlab_session" => session_data } )
        project
28 29 30 31
      end
    end
  end
end