BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
7582bc8b
Commit
7582bc8b
authored
Nov 03, 2017
by
Bob Van Landuyt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Unlink a project from a fork network when it's source was deleted.
We need to close all merge requests coming from the project within the entire fork network.
parent
39d00bdd
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
43 additions
and
5 deletions
+43
-5
fork_network.rb
app/models/fork_network.rb
+4
-0
unlink_fork_service.rb
app/services/projects/unlink_fork_service.rb
+11
-5
fork_network_spec.rb
spec/models/fork_network_spec.rb
+10
-0
unlink_fork_service_spec.rb
spec/services/projects/unlink_fork_service_spec.rb
+18
-0
No files found.
app/models/fork_network.rb
View file @
7582bc8b
...
...
@@ -12,4 +12,8 @@ class ForkNetwork < ActiveRecord::Base
def
find_forks_in
(
other_projects
)
projects
.
where
(
id:
other_projects
)
end
def
merge_requests
MergeRequest
.
where
(
target_project:
projects
)
end
end
app/services/projects/unlink_fork_service.rb
View file @
7582bc8b
...
...
@@ -3,18 +3,24 @@ module Projects
def
execute
return
unless
@project
.
forked?
@project
.
forked_from_project
.
lfs_objects
.
find_each
do
|
lfs_object
|
lfs_object
.
projects
<<
@project
if
fork_source
=
@project
.
fork_source
fork_source
.
lfs_objects
.
find_each
do
|
lfs_object
|
lfs_object
.
projects
<<
@project
end
refresh_forks_count
(
fork_source
)
end
merge_requests
=
@project
.
forked_from_project
.
merge_requests
.
opened
.
from_project
(
@project
)
merge_requests
=
@project
.
fork_network
.
merge_requests
.
opened
.
where
.
not
(
target_project:
@project
)
.
from_project
(
@project
)
merge_requests
.
each
do
|
mr
|
::
MergeRequests
::
CloseService
.
new
(
@project
,
@current_user
).
execute
(
mr
)
end
refresh_forks_count
(
@project
.
forked_from_project
)
@project
.
fork_network_member
.
destroy
@project
.
forked_project_link
.
destroy
end
...
...
spec/models/fork_network_spec.rb
View file @
7582bc8b
...
...
@@ -24,6 +24,16 @@ describe ForkNetwork do
end
end
describe
'#merge_requests'
do
it
'finds merge requests within the fork network'
do
project
=
create
(
:project
)
forked_project
=
fork_project
(
project
)
merge_request
=
create
(
:merge_request
,
source_project:
forked_project
,
target_project:
project
)
expect
(
project
.
fork_network
.
merge_requests
).
to
include
(
merge_request
)
end
end
context
'for a deleted project'
do
it
'keeps the fork network'
do
project
=
create
(
:project
,
:public
)
...
...
spec/services/projects/unlink_fork_service_spec.rb
View file @
7582bc8b
...
...
@@ -12,6 +12,9 @@ describe Projects::UnlinkForkService do
context
'with opened merge request on the source project'
do
let
(
:merge_request
)
{
create
(
:merge_request
,
source_project:
forked_project
,
target_project:
fork_link
.
forked_from_project
)
}
let
(
:merge_request2
)
{
create
(
:merge_request
,
source_project:
forked_project
,
target_project:
fork_project
(
project
))
}
let
(
:merge_request_in_fork
)
{
create
(
:merge_request
,
source_project:
forked_project
,
target_project:
forked_project
)
}
let
(
:mr_close_service
)
{
MergeRequests
::
CloseService
.
new
(
forked_project
,
user
)
}
before
do
...
...
@@ -22,9 +25,14 @@ describe Projects::UnlinkForkService do
it
'close all pending merge requests'
do
expect
(
mr_close_service
).
to
receive
(
:execute
).
with
(
merge_request
)
expect
(
mr_close_service
).
to
receive
(
:execute
).
with
(
merge_request2
)
subject
.
execute
end
it
'does not close merge requests for the project being unlinked'
do
expect
(
mr_close_service
).
not_to
receive
(
:execute
).
with
(
merge_request_in_fork
)
end
end
it
'remove fork relation'
do
...
...
@@ -53,4 +61,14 @@ describe Projects::UnlinkForkService do
expect
(
source
.
forks_count
).
to
be_zero
end
context
'when the original project was deleted'
do
it
'does not fail when the original project is deleted'
do
source
=
forked_project
.
forked_from_project
source
.
destroy
forked_project
.
reload
expect
{
subject
.
execute
}.
not_to
raise_error
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment