move transfer logic out of project to service
This commit is contained in:
parent
0cf0487d65
commit
cba6e92436
2 changed files with 38 additions and 26 deletions
34
app/services/project_transfer_service.rb
Normal file
34
app/services/project_transfer_service.rb
Normal file
|
@ -0,0 +1,34 @@
|
|||
# ProjectTransferService class
|
||||
#
|
||||
# Used for transfer project to another namespace
|
||||
#
|
||||
class ProjectTransferService
|
||||
attr_accessor :project
|
||||
|
||||
def transfer(project, new_namespace)
|
||||
Project.transaction do
|
||||
old_namespace = project.namespace
|
||||
project.namespace = new_namespace
|
||||
|
||||
old_dir = old_namespace.try(:path) || ''
|
||||
new_dir = new_namespace.try(:path) || ''
|
||||
|
||||
old_repo = if old_dir.present?
|
||||
File.join(old_dir, project.path)
|
||||
else
|
||||
project.path
|
||||
end
|
||||
|
||||
if Project.where(path: project.path, namespace_id: new_namespace.try(:id)).present?
|
||||
raise TransferError.new("Project with same path in target namespace already exists")
|
||||
end
|
||||
|
||||
Gitlab::ProjectMover.new(project, old_dir, new_dir).execute
|
||||
|
||||
save!
|
||||
end
|
||||
rescue Gitlab::ProjectMover::ProjectMoveError => ex
|
||||
raise Project::TransferError.new(ex.message)
|
||||
end
|
||||
end
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue