summaryrefslogtreecommitdiff
path: root/app/workers/repository_import_worker.rb
blob: d18c0706b303d7722585914633d43ac8d0aaed0f (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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
class RepositoryImportWorker
  include Sidekiq::Worker
  include Gitlab::ShellAdapter

  sidekiq_options queue: :gitlab_shell

  def perform(project_id)
    project = Project.find(project_id)

    if project.import_url == Project::UNKNOWN_IMPORT_URL
      # In this case, we only want to import issues, not a repository.
      unless project.create_repository
        project.update(import_error: "The repository could not be created.")
        project.import_fail
        return
      end
    else
      begin
        gitlab_shell.import_repository(project.path_with_namespace, project.import_url)
      rescue Gitlab::Shell::Error => e
        project.update(import_error: e.message)
        project.import_fail
        return
      end
    end

    data_import_result =
      case project.import_type
      when 'github'
        Gitlab::GithubImport::Importer.new(project).execute
      when 'gitlab'
        Gitlab::GitlabImport::Importer.new(project).execute
      when 'bitbucket'
        Gitlab::BitbucketImport::Importer.new(project).execute
      when 'google_code'
        Gitlab::GoogleCodeImport::Importer.new(project).execute
      when 'fogbugz'
        Gitlab::FogbugzImport::Importer.new(project).execute
      else
        true
      end

    unless data_import_result
      project.update(import_error: "The remote issue data could not be imported.")
      project.import_fail
      return
    end

    if project.import_type == 'bitbucket'
      Gitlab::BitbucketImport::KeyDeleter.new(project).execute
    end

    project.import_finish
  end
end