summaryrefslogtreecommitdiff
path: root/lib/gitlab/github_import/project_creator.rb
blob: e9725880c5eb2e4cc9b712cfd4a1a375f661ba5d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
module Gitlab
  module GithubImport
    class ProjectCreator
      attr_reader :repo, :namespace, :current_user, :session_data

      def initialize(repo, namespace, current_user, session_data)
        @repo = repo
        @namespace = namespace
        @current_user = current_user
        @session_data = session_data
      end

      def execute
        project = ::Projects::CreateService.new(
          current_user,
          name: repo.name,
          path: repo.name,
          description: repo.description,
          namespace_id: namespace.id,
          visibility_level: repo.private ? Gitlab::VisibilityLevel::PRIVATE : ApplicationSetting.current.default_project_visibility,
          import_type: "github",
          import_source: repo.full_name,
          import_url: repo.clone_url.sub("https://", "https://#{@session_data[:github_access_token]}@")
        ).execute

        # If repo has wiki we'll import it later
        if repo.has_wiki? && project
          project.project_feature.update_attribute(:wiki_access_level, ProjectFeature::DISABLED)
        end

        project
      end
    end
  end
end