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
Jérome Perrin
gitlab-ce
Commits
a9b221d9
Commit
a9b221d9
authored
Apr 03, 2017
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refine method for checking project registry tags
parent
fc5eb315
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
80 additions
and
0 deletions
+80
-0
app/models/project.rb
app/models/project.rb
+20
-0
spec/models/project_spec.rb
spec/models/project_spec.rb
+60
-0
No files found.
app/models/project.rb
View file @
a9b221d9
...
...
@@ -406,6 +406,11 @@ class Project < ActiveRecord::Base
end
end
def
has_container_registry_tags?
container_repositories
.
to_a
.
any?
(
&
:has_tags?
)
||
has_root_container_repository_tags?
end
def
commit
(
ref
=
'HEAD'
)
repository
.
commit
(
ref
)
end
...
...
@@ -1373,4 +1378,19 @@ class Project < ActiveRecord::Base
Project
.
unscoped
.
where
(
pending_delete:
true
).
find_by_full_path
(
path_with_namespace
)
end
##
# This method is here because of support for legacy container repository
# which has exactly the same path like project does, but which might not be
# persisted in `container_repositories` table.
#
def
has_root_container_repository_tags?
return
false
unless
Gitlab
.
config
.
registry
.
enabled
ContainerRegistry
::
Path
.
new
(
self
.
full_path
).
tap
do
|
path
|
ContainerRepository
.
build_from_path
(
path
).
tap
do
|
repository
|
return
repository
.
has_tags?
end
end
end
end
spec/models/project_spec.rb
View file @
a9b221d9
...
...
@@ -1414,6 +1414,66 @@ describe Project, models: true do
end
end
describe
'#has_container_registry_tags?'
do
let
(
:project
)
{
create
(
:empty_project
)
}
context
'when container registry is enabled'
do
before
{
stub_container_registry_config
(
enabled:
true
)
}
context
'when tags are present for multi-level registries'
do
before
do
create
(
:container_repository
,
project:
project
,
name:
'image'
)
stub_container_registry_tags
(
repository:
/image/
,
tags:
%w[latest rc1]
)
end
it
'should have image tags'
do
expect
(
project
).
to
have_container_registry_tags
end
end
context
'when tags are present for root repository'
do
before
do
stub_container_registry_tags
(
repository:
project
.
full_path
,
tags:
%w[latest rc1 pre1]
)
end
it
'should have image tags'
do
expect
(
project
).
to
have_container_registry_tags
end
end
context
'when there are no tags at all'
do
before
do
stub_container_registry_tags
(
repository: :any
,
tags:
[])
end
it
'should not have image tags'
do
expect
(
project
).
not_to
have_container_registry_tags
end
end
end
context
'when container registry is disabled'
do
before
{
stub_container_registry_config
(
enabled:
false
)
}
it
'should not have image tags'
do
expect
(
project
).
not_to
have_container_registry_tags
end
it
'should not check root repository tags'
do
expect
(
project
).
not_to
receive
(
:full_path
)
expect
(
project
).
not_to
have_container_registry_tags
end
it
'should iterate through container repositories'
do
expect
(
project
).
to
receive
(
:container_repositories
)
expect
(
project
).
not_to
have_container_registry_tags
end
end
end
describe
'#latest_successful_builds_for'
do
def
create_pipeline
(
status
=
'success'
)
create
(
:ci_pipeline
,
project:
project
,
...
...
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