debian-mirror-gitlab/app/services/projects/fork_service.rb

36 lines
1 KiB
Ruby
Raw Normal View History

2014-09-02 18:07:02 +05:30
module Projects
class ForkService < BaseService
def execute
2015-09-11 14:41:01 +05:30
new_params = {
forked_from_project_id: @project.id,
visibility_level: allowed_visibility_level,
2015-09-11 14:41:01 +05:30
description: @project.description,
name: @project.name,
path: @project.path,
2015-12-23 02:04:40 +05:30
shared_runners_enabled: @project.shared_runners_enabled,
builds_enabled: @project.builds_enabled,
2015-09-11 14:41:01 +05:30
namespace_id: @params[:namespace].try(:id) || current_user.namespace.id
2015-04-26 12:48:37 +05:30
}
2015-09-11 14:41:01 +05:30
if @project.avatar.present? && @project.avatar.image?
new_params[:avatar] = @project.avatar
2015-04-26 12:48:37 +05:30
end
2015-09-11 14:41:01 +05:30
new_project = CreateService.new(current_user, new_params).execute
new_project
2014-09-02 18:07:02 +05:30
end
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
2014-09-02 18:07:02 +05:30
end
end