Commit f505c753 authored by Douwe Maan's avatar Douwe Maan

Merge branch 'fix_remove_fork_link' into 'master'

Remove fork link closes all merge requests opened on source project

Currently, if you:

- create a fork
- open a merge request on the source project
- remove the fork link

The created MR cannot be closed.

With this MR, all pending MR is closed when the fork link is removed.

See merge request !3189
parents 5e8740ee a6b5b50e
......@@ -128,6 +128,7 @@ v 8.6.0
- Add main language of a project in the list of projects (Tiago Botelho)
- Add #upcoming filter to Milestone filter (Tiago Botelho)
- Add ability to show archived projects on dashboard, explore and group pages
- Remove fork link closes all merge requests opened on source project (Florent Baldino)
- Move group activity to separate page
- Create external users which are excluded of internal and private projects unless access was explicitly granted
- Continue parameters are checked to ensure redirection goes to the same instance
......
......@@ -71,7 +71,7 @@ class ProjectsController < Projects::ApplicationController
def remove_fork
return access_denied! unless can?(current_user, :remove_fork_project, @project)
if @project.unlink_fork
if ::Projects::UnlinkForkService.new(@project, current_user).execute
flash[:notice] = 'The fork relationship has been removed.'
end
end
......
......@@ -135,6 +135,7 @@ class MergeRequest < ActiveRecord::Base
scope :cared, ->(user) { where('assignee_id = :user OR author_id = :user', user: user.id) }
scope :by_milestone, ->(milestone) { where(milestone_id: milestone) }
scope :of_projects, ->(ids) { where(target_project_id: ids) }
scope :from_project, ->(project) { where(source_project_id: project.id) }
scope :merged, -> { with_state(:merged) }
scope :closed_and_merged, -> { with_states(:closed, :merged) }
......
......@@ -931,16 +931,6 @@ class Project < ActiveRecord::Base
self.builds_enabled = true
end
def unlink_fork
if forked?
forked_from_project.lfs_objects.find_each do |lfs_object|
lfs_object.projects << self
end
forked_project_link.destroy
end
end
def any_runners?(&block)
if runners.active.any?(&block)
return true
......
module Projects
class UnlinkForkService < BaseService
def execute
return unless @project.forked?
@project.forked_from_project.lfs_objects.find_each do |lfs_object|
lfs_object.projects << @project
end
merge_requests = @project.forked_from_project.merge_requests.opened.from_project(@project)
merge_requests.each do |mr|
MergeRequests::CloseService.new(@project, @current_user).execute(mr)
end
@project.forked_project_link.destroy
end
end
end
require 'spec_helper'
describe Projects::UnlinkForkService, services: true do
subject { Projects::UnlinkForkService.new(fork_project, user) }
let(:fork_link) { create(:forked_project_link) }
let(:fork_project) { fork_link.forked_to_project }
let(:user) { create(:user) }
context 'with opened merge request on the source project' do
let(:merge_request) { create(:merge_request, source_project: fork_project, target_project: fork_link.forked_from_project) }
let(:mr_close_service) { MergeRequests::CloseService.new(fork_project, user) }
before do
allow(MergeRequests::CloseService).to receive(:new).
with(fork_project, user).
and_return(mr_close_service)
end
it 'close all pending merge requests' do
expect(mr_close_service).to receive(:execute).with(merge_request)
subject.execute
end
end
it 'remove fork relation' do
expect(fork_project.forked_project_link).to receive(:destroy)
subject.execute
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment