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,
|
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
|
2016-09-19 14:28:41 -04:00
|
|
|
return new_project unless new_project.persisted?
|
|
|
|
|
2016-08-01 18:31:21 -04:00
|
|
|
builds_access_level = @project.project_feature.builds_access_level
|
|
|
|
new_project.project_feature.update_attributes(builds_access_level: builds_access_level)
|
|
|
|
|
2017-08-14 09:22:09 -04:00
|
|
|
refresh_forks_count
|
|
|
|
|
2015-04-24 15:37:12 -04:00
|
|
|
new_project
|
2013-05-02 15:30:13 -04:00
|
|
|
end
|
2016-05-24 17:53:53 -04:00
|
|
|
|
|
|
|
private
|
|
|
|
|
2017-08-14 09:22:09 -04:00
|
|
|
def refresh_forks_count
|
|
|
|
Projects::ForksCountService.new(@project).refresh_cache
|
|
|
|
end
|
|
|
|
|
2016-05-24 17:53:53 -04:00
|
|
|
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
|