BigW Consortium Gitlab

repository_fork_worker.rb 1.18 KB
Newer Older
1 2 3
class RepositoryForkWorker
  include Sidekiq::Worker
  include Gitlab::ShellAdapter
4
  include DedicatedSidekiqQueue
5

6
  def perform(project_id, forked_from_repository_storage_path, source_path, target_path)
7 8 9 10
    Gitlab::Metrics.add_event(:fork_repository,
                              source_path: source_path,
                              target_path: target_path)

11 12 13 14 15 16 17
    project = Project.find_by_id(project_id)

    unless project.present?
      logger.error("Project #{project_id} no longer exists!")
      return
    end

18 19
    result = gitlab_shell.fork_repository(forked_from_repository_storage_path, source_path,
                                          project.repository_storage_path, target_path)
20 21
    unless result
      logger.error("Unable to fork project #{project_id} for repository #{source_path} -> #{target_path}")
22
      project.mark_import_as_failed('The project could not be forked.')
23 24 25
      return
    end

26 27
    project.repository.after_import

28
    unless project.valid_repo?
29
      logger.error("Project #{project_id} had an invalid repository after fork")
30
      project.mark_import_as_failed('The forked repository is invalid.')
31
      return
32 33
    end

34
    project.import_finish
35 36
  end
end