2015-09-01 07:56:40 +00:00
|
|
|
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}")
|
2015-11-11 15:22:51 +00:00
|
|
|
project.update(import_error: "The project could not be forked.")
|
2015-09-01 07:56:40 +00:00
|
|
|
project.import_fail
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2015-11-11 15:22:51 +00:00
|
|
|
unless project.valid_repo?
|
2015-09-01 07:56:40 +00:00
|
|
|
logger.error("Project #{id} had an invalid repository after fork")
|
2015-11-11 15:22:51 +00:00
|
|
|
project.update(import_error: "The forked repository is invalid.")
|
|
|
|
project.import_fail
|
|
|
|
return
|
2015-09-01 07:56:40 +00:00
|
|
|
end
|
|
|
|
|
2015-11-11 15:22:51 +00:00
|
|
|
project.import_finish
|
2015-09-01 07:56:40 +00:00
|
|
|
end
|
|
|
|
end
|