2013-03-19 15:37:50 +00:00
|
|
|
module Projects
|
2014-01-16 17:03:42 +00:00
|
|
|
class ForkService < BaseService
|
2013-03-19 15:37:50 +00:00
|
|
|
def execute
|
2015-04-24 19:37:12 +00:00
|
|
|
new_params = {
|
|
|
|
forked_from_project_id: @project.id,
|
2016-05-24 21:53:53 +00:00
|
|
|
visibility_level: allowed_visibility_level,
|
2015-04-24 19:37:12 +00:00
|
|
|
description: @project.description,
|
|
|
|
name: @project.name,
|
|
|
|
path: @project.path,
|
2015-12-04 11:55:23 +00:00
|
|
|
shared_runners_enabled: @project.shared_runners_enabled,
|
|
|
|
builds_enabled: @project.builds_enabled,
|
2015-04-24 19:37:12 +00:00
|
|
|
namespace_id: @params[:namespace].try(:id) || current_user.namespace.id
|
2014-08-25 09:19:52 +00:00
|
|
|
}
|
|
|
|
|
2015-04-24 19:37:12 +00:00
|
|
|
if @project.avatar.present? && @project.avatar.image?
|
|
|
|
new_params[:avatar] = @project.avatar
|
2014-10-03 08:12:44 +00:00
|
|
|
end
|
2014-11-13 17:40:47 +00:00
|
|
|
|
2015-04-24 19:37:12 +00:00
|
|
|
new_project = CreateService.new(current_user, new_params).execute
|
|
|
|
new_project
|
2013-05-02 19:30:13 +00:00
|
|
|
end
|
2016-05-24 21:53:53 +00:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def allowed_visibility_level
|
|
|
|
project_level = @project.visibility_level
|
|
|
|
|
|
|
|
if Gitlab::VisibilityLevel.non_restricted_level?(project_level)
|
|
|
|
project_level
|
|
|
|
else
|
|
|
|
Gitlab::VisibilityLevel.highest_allowed_level
|
|
|
|
end
|
|
|
|
end
|
2013-03-19 15:37:50 +00:00
|
|
|
end
|
|
|
|
end
|