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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
01b2c6e2
Commit
01b2c6e2
authored
Dec 06, 2017
by
Francisco Lopez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Port from CE
parent
aa901225
Changes
6
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
271 additions
and
173 deletions
+271
-173
app/services/projects/fork_service.rb
app/services/projects/fork_service.rb
+29
-7
changelogs/unreleased/fj-40752-forks-api-not-using-services.yml
...logs/unreleased/fj-40752-forks-api-not-using-services.yml
+5
-0
db/post_migrate/20171205190711_reschedule_fork_network_creation_caller.rb
...20171205190711_reschedule_fork_network_creation_caller.rb
+27
-0
db/schema.rb
db/schema.rb
+1
-1
lib/api/projects.rb
lib/api/projects.rb
+11
-10
spec/services/projects/fork_service_spec.rb
spec/services/projects/fork_service_spec.rb
+198
-155
No files found.
app/services/projects/fork_service.rb
View file @
01b2c6e2
module
Projects
class
ForkService
<
BaseService
def
execute
def
execute
(
fork_to_project
=
nil
)
if
fork_to_project
link_existing_project
(
fork_to_project
)
else
fork_new_project
end
end
private
def
link_existing_project
(
fork_to_project
)
return
if
fork_to_project
.
forked?
link_fork_network
(
fork_to_project
)
fork_to_project
end
def
fork_new_project
new_params
=
{
forked_from_project_id:
@project
.
id
,
visibility_level:
allowed_visibility_level
,
...
...
@@ -21,15 +39,11 @@ module Projects
builds_access_level
=
@project
.
project_feature
.
builds_access_level
new_project
.
project_feature
.
update_attributes
(
builds_access_level:
builds_access_level
)
refresh_forks_count
link_fork_network
(
new_project
)
new_project
end
private
def
fork_network
if
@project
.
fork_network
@project
.
fork_network
...
...
@@ -43,9 +57,17 @@ module Projects
end
end
def
link_fork_network
(
new
_project
)
fork_network
.
fork_network_members
.
create
(
project:
new
_project
,
def
link_fork_network
(
fork_to
_project
)
fork_network
.
fork_network_members
.
create
(
project:
fork_to
_project
,
forked_from_project:
@project
)
# TODO: remove this when ForkedProjectLink model is removed
unless
fork_to_project
.
forked_project_link
fork_to_project
.
create_forked_project_link
(
forked_to_project:
fork_to_project
,
forked_from_project:
@project
)
end
refresh_forks_count
end
def
refresh_forks_count
...
...
changelogs/unreleased/fj-40752-forks-api-not-using-services.yml
0 → 100644
View file @
01b2c6e2
---
title
:
Using appropiate services in the API for managing forks
merge_request
:
15709
author
:
type
:
fixed
db/post_migrate/20171205190711_reschedule_fork_network_creation_caller.rb
0 → 100644
View file @
01b2c6e2
class
RescheduleForkNetworkCreationCaller
<
ActiveRecord
::
Migration
include
Gitlab
::
Database
::
MigrationHelpers
DOWNTIME
=
false
MIGRATION
=
'PopulateForkNetworksRange'
.
freeze
BATCH_SIZE
=
100
DELAY_INTERVAL
=
15
.
seconds
disable_ddl_transaction!
class
ForkedProjectLink
<
ActiveRecord
::
Base
include
EachBatch
self
.
table_name
=
'forked_project_links'
end
def
up
say
'Populating the `fork_networks` based on existing `forked_project_links`'
queue_background_migration_jobs_by_range_at_intervals
(
ForkedProjectLink
,
MIGRATION
,
DELAY_INTERVAL
,
batch_size:
BATCH_SIZE
)
end
def
down
# nothing
end
end
db/schema.rb
View file @
01b2c6e2
...
...
@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord
::
Schema
.
define
(
version:
20171
124182517
)
do
ActiveRecord
::
Schema
.
define
(
version:
20171
205190711
)
do
# These are extensions that must be enabled in order to support this database
enable_extension
"plpgsql"
...
...
lib/api/projects.rb
View file @
01b2c6e2
...
...
@@ -379,15 +379,16 @@ module API
post
":id/fork/:forked_from_id"
do
authenticated_as_admin!
forked_from_project
=
find_project!
(
params
[
:forked_from_id
])
not_found!
(
"Source Project"
)
unless
forked_from_project
fork_from_project
=
find_project!
(
params
[
:forked_from_id
])
if
user_project
.
forked_from_project
.
nil?
user_project
.
create_forked_project_link
(
forked_to_project_id:
user_project
.
id
,
forked_from_project_id:
forked_from_project
.
id
)
not_found!
(
"Source Project"
)
unless
fork_from_project
::
Projects
::
ForksCountService
.
new
(
forked_from_project
).
refresh_cache
result
=
::
Projects
::
ForkService
.
new
(
fork_from_project
,
current_user
).
execute
(
user_project
)
if
result
present
user_project
.
reload
,
with:
Entities
::
Project
else
render_api_error!
(
"Project already forked"
,
409
)
render_api_error!
(
"Project already forked"
,
409
)
if
user_project
.
forked?
end
end
...
...
@@ -395,11 +396,11 @@ module API
delete
":id/fork"
do
authorize!
:remove_fork_project
,
user_project
if
user_project
.
forked?
destroy_conditionally!
(
user_project
.
forked_project_link
)
else
not_modified!
result
=
destroy_conditionally!
(
user_project
)
do
::
Projects
::
UnlinkForkService
.
new
(
user_project
,
current_user
).
execute
end
result
?
status
(
204
)
:
not_modified!
end
desc
'Share the project with a group'
do
...
...
spec/services/projects/fork_service_spec.rb
View file @
01b2c6e2
This diff is collapsed.
Click to expand it.
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