diff options
author | Bob Van Landuyt <bob@vanlanduyt.co> | 2017-09-28 17:38:12 +0300 |
---|---|---|
committer | Bob Van Landuyt <bob@vanlanduyt.co> | 2017-10-07 12:46:23 +0300 |
commit | d328007214786c7137c31d2c73e9ee76b025e6ed (patch) | |
tree | fe4ec118148b7397890f86c6b2982ce667086c38 /app/services/projects/fork_service.rb | |
parent | 20727db1702849b78e6714197f16f602f68cecf8 (diff) |
Create a fork network when forking a project
When no fork network exists for the source projects, we create a new
one with the correct source
Diffstat (limited to 'app/services/projects/fork_service.rb')
-rw-r--r-- | app/services/projects/fork_service.rb | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/app/services/projects/fork_service.rb b/app/services/projects/fork_service.rb index ad67e68a86a..eb5cce5ab98 100644 --- a/app/services/projects/fork_service.rb +++ b/app/services/projects/fork_service.rb @@ -23,11 +23,31 @@ module Projects refresh_forks_count + link_fork_network(new_project) + new_project end private + def fork_network + if @project.fork_network + @project.fork_network + elsif forked_from_project = @project.forked_from_project + # TODO: remove this case when all background migrations have completed + # this only happens when a project had a `forked_project_link` that was + # not migrated to the `fork_network` relation + forked_from_project.fork_network || forked_from_project.create_root_of_fork_network + else + @project.create_root_of_fork_network + end + end + + def link_fork_network(new_project) + fork_network.fork_network_members.create(project: new_project, + forked_from_project: @project) + end + def refresh_forks_count Projects::ForksCountService.new(@project).refresh_cache end |