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
Boxiang Sun
gitlab-ce
Commits
f90b27da
Commit
f90b27da
authored
Oct 03, 2017
by
Bob Van Landuyt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Find forks within users/namespaces using fork memberships
parent
81605504
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
70 additions
and
10 deletions
+70
-10
app/models/fork_network.rb
app/models/fork_network.rb
+4
-0
app/models/namespace.rb
app/models/namespace.rb
+3
-1
app/models/project.rb
app/models/project.rb
+5
-0
app/models/user.rb
app/models/user.rb
+1
-9
spec/factories/fork_networks.rb
spec/factories/fork_networks.rb
+5
-0
spec/models/fork_network_spec.rb
spec/models/fork_network_spec.rb
+12
-0
spec/models/namespace_spec.rb
spec/models/namespace_spec.rb
+23
-0
spec/models/user_spec.rb
spec/models/user_spec.rb
+17
-0
No files found.
app/models/fork_network.rb
View file @
f90b27da
...
@@ -8,4 +8,8 @@ class ForkNetwork < ActiveRecord::Base
...
@@ -8,4 +8,8 @@ class ForkNetwork < ActiveRecord::Base
def
add_root_as_member
def
add_root_as_member
projects
<<
root_project
projects
<<
root_project
end
end
def
find_forks_in
(
other_projects
)
projects
.
where
(
id:
other_projects
)
end
end
end
app/models/namespace.rb
View file @
f90b27da
...
@@ -139,7 +139,9 @@ class Namespace < ActiveRecord::Base
...
@@ -139,7 +139,9 @@ class Namespace < ActiveRecord::Base
end
end
def
find_fork_of
(
project
)
def
find_fork_of
(
project
)
projects
.
joins
(
:forked_project_link
).
find_by
(
'forked_project_links.forked_from_project_id = ?'
,
project
.
id
)
return
nil
unless
project
.
fork_network
project
.
fork_network
.
find_forks_in
(
projects
).
first
end
end
def
lfs_enabled?
def
lfs_enabled?
...
...
app/models/project.rb
View file @
f90b27da
...
@@ -1009,6 +1009,11 @@ class Project < ActiveRecord::Base
...
@@ -1009,6 +1009,11 @@ class Project < ActiveRecord::Base
end
end
def
forked?
def
forked?
return
true
if
fork_network
&&
fork_network
.
root_project
!=
self
# TODO: Use only the above conditional using the `fork_network`
# This is the old conditional that looks at the `forked_project_link`, we
# fall back to this while we're migrating the new models
!
(
forked_project_link
.
nil?
||
forked_project_link
.
forked_from_project
.
nil?
)
!
(
forked_project_link
.
nil?
||
forked_project_link
.
forked_from_project
.
nil?
)
end
end
...
...
app/models/user.rb
View file @
f90b27da
...
@@ -697,15 +697,7 @@ class User < ActiveRecord::Base
...
@@ -697,15 +697,7 @@ class User < ActiveRecord::Base
end
end
def
fork_of
(
project
)
def
fork_of
(
project
)
links
=
ForkedProjectLink
.
where
(
namespace
.
find_fork_of
(
project
)
forked_from_project_id:
project
,
forked_to_project_id:
personal_projects
.
unscope
(
:order
)
)
if
links
.
any?
links
.
first
.
forked_to_project
else
nil
end
end
end
def
ldap_user?
def
ldap_user?
...
...
spec/factories/fork_networks.rb
0 → 100644
View file @
f90b27da
FactoryGirl
.
define
do
factory
:fork_network
do
association
:root_project
,
factory: :project
end
end
spec/models/fork_network_spec.rb
View file @
f90b27da
...
@@ -12,6 +12,18 @@ describe ForkNetwork do
...
@@ -12,6 +12,18 @@ describe ForkNetwork do
end
end
end
end
describe
'#find_fork_in'
do
it
'finds all fork of the current network in al collection'
do
network
=
create
(
:fork_network
)
root_project
=
network
.
root_project
another_project
=
fork_project
(
root_project
)
create
(
:project
)
expect
(
network
.
find_forks_in
(
Project
.
all
))
.
to
contain_exactly
(
another_project
,
root_project
)
end
end
context
'for a deleted project'
do
context
'for a deleted project'
do
it
'keeps the fork network'
do
it
'keeps the fork network'
do
project
=
create
(
:project
,
:public
)
project
=
create
(
:project
,
:public
)
...
...
spec/models/namespace_spec.rb
View file @
f90b27da
require
'spec_helper'
require
'spec_helper'
describe
Namespace
do
describe
Namespace
do
include
ProjectForksHelper
let!
(
:namespace
)
{
create
(
:namespace
)
}
let!
(
:namespace
)
{
create
(
:namespace
)
}
describe
'associations'
do
describe
'associations'
do
...
@@ -520,4 +522,25 @@ describe Namespace do
...
@@ -520,4 +522,25 @@ describe Namespace do
end
end
end
end
end
end
describe
'#has_forks_of?'
do
let
(
:project
)
{
create
(
:project
,
:public
)
}
let!
(
:forked_project
)
{
fork_project
(
project
,
namespace
.
owner
,
namespace:
namespace
)
}
before
do
# Reset the fork network relation
project
.
reload
end
it
'knows if there is a direct fork in the namespace'
do
expect
(
namespace
.
find_fork_of
(
project
)).
to
eq
(
forked_project
)
end
it
'knows when there is as fork-of-fork in the namespace'
do
other_namespace
=
create
(
:namespace
)
other_fork
=
fork_project
(
forked_project
,
other_namespace
.
owner
,
namespace:
other_namespace
)
expect
(
other_namespace
.
find_fork_of
(
project
)).
to
eq
(
other_fork
)
end
end
end
end
spec/models/user_spec.rb
View file @
f90b27da
...
@@ -1456,6 +1456,23 @@ describe User do
...
@@ -1456,6 +1456,23 @@ describe User do
end
end
end
end
describe
'#fork_of'
do
let
(
:user
)
{
create
(
:user
)
}
it
"returns a user's fork of a project"
do
project
=
create
(
:project
,
:public
)
user_fork
=
fork_project
(
project
,
user
,
namespace:
user
.
namespace
)
expect
(
user
.
fork_of
(
project
)).
to
eq
(
user_fork
)
end
it
'returns nil if the project does not have a fork network'
do
project
=
create
(
:project
)
expect
(
user
.
fork_of
(
project
)).
to
be_nil
end
end
describe
'#can_be_removed?'
do
describe
'#can_be_removed?'
do
subject
{
create
(
:user
)
}
subject
{
create
(
:user
)
}
...
...
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