2018-11-18 11:00:15 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
module Projects
|
|
|
|
class UnlinkForkService < BaseService
|
2018-12-05 23:21:45 +05:30
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
2016-06-02 11:05:42 +05:30
|
|
|
def execute
|
|
|
|
return unless @project.forked?
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
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-06-02 11:05:42 +05:30
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
merge_requests = @project.fork_network
|
|
|
|
.merge_requests
|
|
|
|
.opened
|
|
|
|
.where.not(target_project: @project)
|
|
|
|
.from_project(@project)
|
2016-06-02 11:05:42 +05:30
|
|
|
|
|
|
|
merge_requests.each do |mr|
|
2017-09-10 17:25:29 +05:30
|
|
|
::MergeRequests::CloseService.new(@project, @current_user).execute(mr)
|
2016-06-02 11:05:42 +05:30
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
@project.fork_network_member.destroy
|
2016-06-02 11:05:42 +05:30
|
|
|
end
|
2018-12-05 23:21:45 +05:30
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2017-09-10 17:25:29 +05:30
|
|
|
|
|
|
|
def refresh_forks_count(project)
|
|
|
|
Projects::ForksCountService.new(project).refresh_cache
|
|
|
|
end
|
2016-06-02 11:05:42 +05:30
|
|
|
end
|
|
|
|
end
|