debian-mirror-gitlab/app/workers/repository_fork_worker.rb

32 lines
1 KiB
Ruby
Raw Normal View History

2015-09-25 12:07:36 +05:30
class RepositoryForkWorker
2018-03-17 18:26:18 +05:30
include ApplicationWorker
2015-09-25 12:07:36 +05:30
include Gitlab::ShellAdapter
2018-03-17 18:26:18 +05:30
include ProjectStartImport
include ProjectImportOptions
2016-09-13 17:45:13 +05:30
2018-03-17 18:26:18 +05:30
def perform(project_id, forked_from_repository_storage_path, source_disk_path)
2017-09-10 17:25:29 +05:30
project = Project.find(project_id)
2015-09-25 12:07:36 +05:30
2018-03-17 18:26:18 +05:30
return unless start_fork(project)
2015-09-25 12:07:36 +05:30
2018-03-17 18:26:18 +05:30
Gitlab::Metrics.add_event(:fork_repository,
source_path: source_disk_path,
target_path: project.disk_path)
2015-09-25 12:07:36 +05:30
2018-03-17 18:26:18 +05:30
result = gitlab_shell.fork_repository(forked_from_repository_storage_path, source_disk_path,
project.repository_storage_path, project.disk_path)
raise "Unable to fork project #{project_id} for repository #{source_disk_path} -> #{project.disk_path}" unless result
2017-09-10 17:25:29 +05:30
2018-03-17 18:26:18 +05:30
project.after_import
2017-09-10 17:25:29 +05:30
end
private
2018-03-17 18:26:18 +05:30
def start_fork(project)
return true if start(project)
Rails.logger.info("Project #{project.full_path} was in inconsistent state (#{project.import_status}) while forking.")
false
2015-09-25 12:07:36 +05:30
end
end