BigW Consortium Gitlab

repository_fork_worker.rb 952 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
class RepositoryForkWorker
  include Sidekiq::Worker
  include Gitlab::ShellAdapter

  sidekiq_options queue: :gitlab_shell

  def perform(project_id, source_path, target_path)
    project = Project.find_by_id(project_id)

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

    result = gitlab_shell.fork_repository(source_path, target_path)
    unless result
      logger.error("Unable to fork project #{project_id} for repository #{source_path} -> #{target_path}")
18
      project.update(import_error: "The project could not be forked.")
19 20 21 22
      project.import_fail
      return
    end

23 24
    project.repository.after_import

25
    unless project.valid_repo?
26
      logger.error("Project #{project_id} had an invalid repository after fork")
27 28 29
      project.update(import_error: "The forked repository is invalid.")
      project.import_fail
      return
30 31
    end

32
    project.import_finish
33 34
  end
end