gitlab-org--gitlab-foss/app/services/projects/unlink_fork_service.rb

33 lines
931 B
Ruby
Raw Normal View History

2016-03-22 10:34:35 -04:00
module Projects
class UnlinkForkService < BaseService
def execute
return unless @project.forked?
if fork_source = @project.fork_source
fork_source.lfs_objects.find_each do |lfs_object|
lfs_object.projects << @project unless lfs_object.projects.include?(@project)
end
refresh_forks_count(fork_source)
2016-03-22 10:34:35 -04:00
end
merge_requests = @project.fork_network
.merge_requests
.opened
.where.not(target_project: @project)
.from_project(@project)
2016-03-22 10:34:35 -04:00
merge_requests.each do |mr|
2017-06-13 18:12:31 -04:00
::MergeRequests::CloseService.new(@project, @current_user).execute(mr)
2016-03-22 10:34:35 -04:00
end
@project.fork_network_member.destroy
@project.forked_project_link.destroy
2016-03-22 10:34:35 -04:00
end
def refresh_forks_count(project)
Projects::ForksCountService.new(project).refresh_cache
end
2016-03-22 10:34:35 -04:00
end
end