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