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
6ef27f77
Commit
6ef27f77
authored
May 10, 2019
by
Grzegorz Bizon
Committed by
Filipa Lacerda
May 24, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Expose build environment latest deployable name and path
parent
a96b9ebf
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
36 additions
and
4 deletions
+36
-4
app/serializers/deployment_entity.rb
app/serializers/deployment_entity.rb
+20
-1
spec/fixtures/api/schemas/environment.json
spec/fixtures/api/schemas/environment.json
+5
-1
spec/serializers/build_details_entity_spec.rb
spec/serializers/build_details_entity_spec.rb
+1
-1
spec/serializers/deployment_entity_spec.rb
spec/serializers/deployment_entity_spec.rb
+10
-1
No files found.
app/serializers/deployment_entity.rb
View file @
6ef27f77
...
@@ -22,8 +22,18 @@ class DeploymentEntity < Grape::Entity
...
@@ -22,8 +22,18 @@ class DeploymentEntity < Grape::Entity
expose
:last?
expose
:last?
expose
:user
,
using:
UserEntity
expose
:user
,
using:
UserEntity
expose
:deployable
do
|
deployment
,
opts
|
deployment
.
deployable
.
yield_self
do
|
deployable
|
if
include_details?
JobEntity
.
represent
(
deployable
,
opts
)
elsif
can_read_deployables?
{
name:
deployable
.
name
,
build_path:
project_job_path
(
deployable
.
project
,
deployable
)
}
end
end
end
expose
:commit
,
using:
CommitEntity
,
if:
->
(
*
)
{
include_details?
}
expose
:commit
,
using:
CommitEntity
,
if:
->
(
*
)
{
include_details?
}
expose
:deployable
,
using:
JobEntity
,
if:
->
(
*
)
{
include_details?
}
expose
:manual_actions
,
using:
JobEntity
,
if:
->
(
*
)
{
include_details?
&&
can_create_deployment?
}
expose
:manual_actions
,
using:
JobEntity
,
if:
->
(
*
)
{
include_details?
&&
can_create_deployment?
}
expose
:scheduled_actions
,
using:
JobEntity
,
if:
->
(
*
)
{
include_details?
&&
can_create_deployment?
}
expose
:scheduled_actions
,
using:
JobEntity
,
if:
->
(
*
)
{
include_details?
&&
can_create_deployment?
}
...
@@ -36,4 +46,13 @@ class DeploymentEntity < Grape::Entity
...
@@ -36,4 +46,13 @@ class DeploymentEntity < Grape::Entity
def
can_create_deployment?
def
can_create_deployment?
can?
(
request
.
current_user
,
:create_deployment
,
request
.
project
)
can?
(
request
.
current_user
,
:create_deployment
,
request
.
project
)
end
end
def
can_read_deployables?
##
# We intentionally do not check `:read_build, deployment.deployable`
# because it triggers a policy evaluation that involves multiple
# Gitaly calls that might not be cached.
#
can?
(
request
.
current_user
,
:read_build
,
request
.
project
)
end
end
end
spec/fixtures/api/schemas/environment.json
View file @
6ef27f77
...
@@ -31,7 +31,11 @@
...
@@ -31,7 +31,11 @@
"last_deployment"
:
{
"last_deployment"
:
{
"oneOf"
:
[
"oneOf"
:
[
{
"type"
:
"null"
},
{
"type"
:
"null"
},
{
"$ref"
:
"deployment.json"
}
{
"$ref"
:
"deployment.json"
},
{
"name"
:
{
"type"
:
"string"
},
"build_path"
:
{
"type"
:
"string"
}
}
]
]
}
}
},
},
...
...
spec/serializers/build_details_entity_spec.rb
View file @
6ef27f77
...
@@ -142,7 +142,7 @@ describe BuildDetailsEntity do
...
@@ -142,7 +142,7 @@ describe BuildDetailsEntity do
response
=
subject
.
with_indifferent_access
response
=
subject
.
with_indifferent_access
response
.
dig
(
:deployment_status
,
:environment
,
:last_deployment
).
tap
do
|
deployment
|
response
.
dig
(
:deployment_status
,
:environment
,
:last_deployment
).
tap
do
|
deployment
|
expect
(
deployment
).
not_to
include
(
:commit
,
:
deployable
,
:
manual_actions
,
:scheduled_actions
)
expect
(
deployment
).
not_to
include
(
:commit
,
:manual_actions
,
:scheduled_actions
)
end
end
end
end
end
end
...
...
spec/serializers/deployment_entity_spec.rb
View file @
6ef27f77
...
@@ -93,13 +93,22 @@ describe DeploymentEntity do
...
@@ -93,13 +93,22 @@ describe DeploymentEntity do
end
end
context
'when deployment details serialization was disabled'
do
context
'when deployment details serialization was disabled'
do
include
Gitlab
::
Routing
let
(
:entity
)
do
let
(
:entity
)
do
described_class
.
new
(
deployment
,
request:
request
,
deployment_details:
false
)
described_class
.
new
(
deployment
,
request:
request
,
deployment_details:
false
)
end
end
it
'does not serialize deployment details'
do
it
'does not serialize deployment details'
do
expect
(
subject
.
with_indifferent_access
)
expect
(
subject
.
with_indifferent_access
)
.
not_to
include
(
:commit
,
:deployable
,
:manual_actions
,
:scheduled_actions
)
.
not_to
include
(
:commit
,
:manual_actions
,
:scheduled_actions
)
end
it
'only exposes deployable name and path'
do
project_job_path
(
project
,
deployment
.
deployable
).
tap
do
|
path
|
expect
(
subject
.
fetch
(
:deployable
))
.
to
eq
(
'name'
=>
'test'
,
'build_path'
=>
path
)
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