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
003a51d1
Commit
003a51d1
authored
Mar 30, 2017
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Check container repository exists for a given path
parent
031122eb
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
54 additions
and
18 deletions
+54
-18
lib/container_registry/path.rb
lib/container_registry/path.rb
+9
-2
spec/lib/container_registry/path_spec.rb
spec/lib/container_registry/path_spec.rb
+29
-1
spec/services/container_registry/create_repository_service_spec.rb
...ices/container_registry/create_repository_service_spec.rb
+16
-15
No files found.
lib/container_registry/path.rb
View file @
003a51d1
...
@@ -33,8 +33,15 @@ module ContainerRegistry
...
@@ -33,8 +33,15 @@ module ContainerRegistry
end
end
end
end
def
has_project?
repository_project
.
present?
end
def
has_repository?
def
has_repository?
# ContainerRepository.find_by_full_path(@path).present?
return
false
unless
has_project?
repository_project
.
container_repositories
.
where
(
name:
repository_name
).
any?
end
end
def
repository_project
def
repository_project
...
@@ -42,7 +49,7 @@ module ContainerRegistry
...
@@ -42,7 +49,7 @@ module ContainerRegistry
end
end
def
repository_name
def
repository_name
return
unless
repository_project
return
unless
has_project?
@path
.
remove
(
%r(^?
#{
Regexp
.
escape
(
repository_project
.
full_path
)
}
/?)
)
@path
.
remove
(
%r(^?
#{
Regexp
.
escape
(
repository_project
.
full_path
)
}
/?)
)
end
end
...
...
spec/lib/container_registry/path_spec.rb
View file @
003a51d1
...
@@ -39,7 +39,7 @@ describe ContainerRegistry::Path do
...
@@ -39,7 +39,7 @@ describe ContainerRegistry::Path do
it
'is not valid'
do
it
'is not valid'
do
expect
(
subject
).
not_to
be_valid
expect
(
subject
).
not_to
be_valid
end
end
end
end
context
'when path has more than allowed number of components'
do
context
'when path has more than allowed number of components'
do
let
(
:path
)
{
'a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/r/s/t/u/w/y/z'
}
let
(
:path
)
{
'a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/r/s/t/u/w/y/z'
}
...
@@ -58,6 +58,34 @@ describe ContainerRegistry::Path do
...
@@ -58,6 +58,34 @@ describe ContainerRegistry::Path do
end
end
end
end
describe
'#has_repository?'
do
context
'when project exists'
do
let
(
:project
)
{
create
(
:empty_project
)
}
let
(
:path
)
{
"
#{
project
.
full_path
}
/my/image"
}
context
'when path already has matching repository'
do
before
do
create
(
:container_repository
,
project:
project
,
name:
'my/image'
)
end
it
{
is_expected
.
to
have_repository
}
it
{
is_expected
.
to
have_project
}
end
context
'when path does not have matching repository'
do
it
{
is_expected
.
not_to
have_repository
}
it
{
is_expected
.
to
have_project
}
end
end
context
'when project does not exist'
do
let
(
:path
)
{
'some/project/my/image'
}
it
{
is_expected
.
not_to
have_repository
}
it
{
is_expected
.
not_to
have_project
}
end
end
describe
'#repository_project'
do
describe
'#repository_project'
do
let
(
:group
)
{
create
(
:group
,
path:
'some_group'
)
}
let
(
:group
)
{
create
(
:group
,
path:
'some_group'
)
}
...
...
spec/services/container_registry/create_repository_service_spec.rb
View file @
003a51d1
...
@@ -14,18 +14,6 @@ describe ContainerRegistry::CreateRepositoryService, '#execute' do
...
@@ -14,18 +14,6 @@ describe ContainerRegistry::CreateRepositoryService, '#execute' do
stub_container_registry_config
(
enabled:
true
)
stub_container_registry_config
(
enabled:
true
)
end
end
context
'when container repository already exists'
do
before
do
create
(
:container_repository
,
project:
project
,
name:
'my/image'
)
end
it
'does not create container repository again'
do
expect
{
service
.
execute
(
path
)
}
.
to
raise_error
(
Gitlab
::
Access
::
AccessDeniedError
)
.
and
change
{
ContainerRepository
.
count
}.
by
(
0
)
end
end
context
'when repository is created by an user'
do
context
'when repository is created by an user'
do
context
'when user has no ability to create a repository'
do
context
'when user has no ability to create a repository'
do
it
'does not create a new container repository'
do
it
'does not create a new container repository'
do
...
@@ -40,9 +28,22 @@ describe ContainerRegistry::CreateRepositoryService, '#execute' do
...
@@ -40,9 +28,22 @@ describe ContainerRegistry::CreateRepositoryService, '#execute' do
project
.
add_developer
(
user
)
project
.
add_developer
(
user
)
end
end
it
'creates a new container repository'
do
context
'when repository already exists'
do
expect
{
service
.
execute
(
path
)
}
before
do
.
to
change
{
project
.
container_repositories
.
count
}.
by
(
1
)
create
(
:container_repository
,
project:
project
,
name:
'my/image'
)
end
it
'does not create container repository again'
do
expect
{
service
.
execute
(
path
)
}
.
to_not
change
{
ContainerRepository
.
count
}
end
end
context
'when repository does not exist yet'
do
it
'creates a new container repository'
do
expect
{
service
.
execute
(
path
)
}
.
to
change
{
project
.
container_repositories
.
count
}.
by
(
1
)
end
end
end
end
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