BigW Consortium Gitlab

repository_import_worker.rb 1.55 KB
Newer Older
1 2 3 4 5 6 7 8
class RepositoryImportWorker
  include Sidekiq::Worker
  include Gitlab::ShellAdapter

  sidekiq_options queue: :gitlab_shell

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

Jared Szechy committed
10 11
    unless project.import_url == Project::UNKNOWN_IMPORT_URL
      import_result = gitlab_shell.send(:import_repository,
12 13
                               project.path_with_namespace,
                               project.import_url)
Jared Szechy committed
14 15 16 17 18 19
      return project.import_fail unless import_result
    else
      unless project.create_repository
        return project.import_fail
      end
    end
20

Jared Szechy committed
21 22 23 24 25 26 27 28 29 30 31 32 33 34
    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
35
    return project.import_fail unless data_import_result
Valery Sizov committed
36

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

39 40
    project.import_finish
    project.save
41
    ProjectCacheWorker.perform_async(project.id)
42
  end
43
end