Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Tatuya Kamada
gitlab-ce
Commits
fa4126ac
Commit
fa4126ac
authored
Mar 22, 2016
by
Baldinof
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move unlink fork logic to a service
parent
436caf4e
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
52 additions
and
40 deletions
+52
-40
app/controllers/projects_controller.rb
app/controllers/projects_controller.rb
+1
-1
app/models/project.rb
app/models/project.rb
+0
-20
app/services/projects/unlink_fork_service.rb
app/services/projects/unlink_fork_service.rb
+19
-0
spec/models/project_spec.rb
spec/models/project_spec.rb
+0
-19
spec/services/projects/unlink_fork_service_spec.rb
spec/services/projects/unlink_fork_service_spec.rb
+32
-0
No files found.
app/controllers/projects_controller.rb
View file @
fa4126ac
...
...
@@ -71,7 +71,7 @@ class ProjectsController < ApplicationController
def
remove_fork
return
access_denied!
unless
can?
(
current_user
,
:remove_fork_project
,
@project
)
if
@project
.
unlink_fork
(
current_user
)
if
::
Projects
::
UnlinkForkService
.
new
(
@project
,
current_user
).
execute
flash
[
:notice
]
=
'The fork relationship has been removed.'
end
end
...
...
app/models/project.rb
View file @
fa4126ac
...
...
@@ -917,26 +917,6 @@ class Project < ActiveRecord::Base
self
.
builds_enabled
=
true
end
def
unlink_fork
(
user
)
if
forked?
forked_from_project
.
lfs_objects
.
find_each
do
|
lfs_object
|
lfs_object
.
projects
<<
self
end
merge_requests
=
forked_from_project
.
merge_requests
.
opened
.
from_project
(
self
)
unless
merge_requests
.
empty?
close_service
=
MergeRequests
::
CloseService
.
new
(
self
,
user
)
merge_requests
.
each
do
|
mr
|
close_service
.
execute
(
mr
)
end
end
forked_project_link
.
destroy
end
end
def
any_runners?
(
&
block
)
if
runners
.
active
.
any?
(
&
block
)
return
true
...
...
app/services/projects/unlink_fork_service.rb
0 → 100644
View file @
fa4126ac
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
<<
self
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
spec/models/project_spec.rb
View file @
fa4126ac
...
...
@@ -699,25 +699,6 @@ describe Project, models: true do
end
end
describe
'#unlink_fork'
do
let
(
:fork_link
)
{
create
(
:forked_project_link
)
}
let
(
:fork_project
)
{
fork_link
.
forked_to_project
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:merge_request
)
{
create
(
:merge_request
,
source_project:
fork_project
,
target_project:
fork_link
.
forked_from_project
)
}
let!
(
:close_service
)
{
MergeRequests
::
CloseService
.
new
(
fork_project
,
user
)
}
it
'remove fork relation and close all pending merge requests'
do
allow
(
MergeRequests
::
CloseService
).
to
receive
(
:new
).
with
(
fork_project
,
user
).
and_return
(
close_service
)
expect
(
close_service
).
to
receive
(
:execute
).
with
(
merge_request
)
expect
(
fork_project
.
forked_project_link
).
to
receive
(
:destroy
)
fork_project
.
unlink_fork
(
user
)
end
end
describe
'.search_by_title'
do
let
(
:project
)
{
create
(
:project
,
name:
'kittens'
)
}
...
...
spec/services/projects/unlink_fork_service_spec.rb
0 → 100644
View file @
fa4126ac
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
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