summaryrefslogtreecommitdiff
path: root/app/workers/repository_import_worker.rb
blob: f2ba2e15e7b2f7e7ef4f3e028ee13d311aed8792 (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
class RepositoryImportWorker
  include Sidekiq::Worker
  include Gitlab::ShellAdapter

  sidekiq_options queue: :gitlab_shell

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

    import_result = gitlab_shell.send(:import_repository,
                               project.path_with_namespace,
                               project.import_url)
    return project.import_fail unless import_result

    data_import_result =  if project.import_type == 'github'
                            Gitlab::GithubImport::Importer.new(project).execute
                          elsif project.import_type == 'gitlab'
                            Gitlab::GitlabImport::Importer.new(project).execute
                          elsif project.import_type == 'bitbucket'
                            Gitlab::BitbucketImport::Importer.new(project).execute
                          elsif project.import_type == 'google_code'
                            Gitlab::GoogleCodeImport::Importer.new(project).execute
                          else
                            true
                          end
    return project.import_fail unless data_import_result

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

    project.import_finish
    project.save
    ProjectCacheWorker.perform_async(project.id)
  end
end