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
0527bfcd
Commit
0527bfcd
authored
Nov 24, 2020
by
Shinya Maeda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Expose upcoming deployment
This commit exposes the upcoming deployment in EnvironmentEntity.
parent
e08701cb
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
85 additions
and
4 deletions
+85
-4
app/models/environment.rb
app/models/environment.rb
+1
-0
app/serializers/environment_entity.rb
app/serializers/environment_entity.rb
+8
-0
changelogs/unreleased/expose-upcoming-deployment.yml
changelogs/unreleased/expose-upcoming-deployment.yml
+5
-0
spec/models/environment_spec.rb
spec/models/environment_spec.rb
+17
-0
spec/serializers/environment_entity_spec.rb
spec/serializers/environment_entity_spec.rb
+54
-4
No files found.
app/models/environment.rb
View file @
0527bfcd
...
...
@@ -32,6 +32,7 @@ class Environment < ApplicationRecord
has_one
:last_visible_deployment
,
->
{
visible
.
distinct_on_environment
},
inverse_of: :environment
,
class_name:
'Deployment'
has_one
:last_visible_deployable
,
through: :last_visible_deployment
,
source:
'deployable'
,
source_type:
'CommitStatus'
has_one
:last_visible_pipeline
,
through: :last_visible_deployable
,
source:
'pipeline'
has_one
:upcoming_deployment
,
->
{
running
.
order
(
'deployments.id DESC'
)
},
class_name:
'Deployment'
has_one
:latest_opened_most_severe_alert
,
->
{
order_severity_with_open_prometheus_alert
},
class_name:
'AlertManagement::Alert'
,
inverse_of: :environment
before_validation
:nullify_external_url
...
...
app/serializers/environment_entity.rb
View file @
0527bfcd
...
...
@@ -3,6 +3,9 @@
class
EnvironmentEntity
<
Grape
::
Entity
include
RequestAwareEntity
UNNECESSARY_ENTRIES_FOR_UPCOMING_DEPLOYMENT
=
%i[manual_actions scheduled_actions playable_build cluster]
.
freeze
expose
:id
expose
:global_id
do
|
environment
|
...
...
@@ -17,6 +20,11 @@ class EnvironmentEntity < Grape::Entity
expose
:last_deployment
,
using:
DeploymentEntity
expose
:stop_action_available?
,
as: :has_stop_action
expose
:upcoming_deployment
,
expose_nil:
false
do
|
environment
,
ops
|
DeploymentEntity
.
represent
(
environment
.
upcoming_deployment
,
ops
.
merge
(
except:
UNNECESSARY_ENTRIES_FOR_UPCOMING_DEPLOYMENT
))
end
expose
:metrics_path
,
if:
->
(
*
)
{
environment
.
has_metrics?
}
do
|
environment
|
metrics_project_environment_path
(
environment
.
project
,
environment
)
end
...
...
changelogs/unreleased/expose-upcoming-deployment.yml
0 → 100644
View file @
0527bfcd
---
title
:
Expose upcoming deployment in environment.json
merge_request
:
48449
author
:
type
:
added
spec/models/environment_spec.rb
View file @
0527bfcd
...
...
@@ -19,6 +19,7 @@ RSpec.describe Environment, :use_clean_rails_memory_store_caching do
it
{
is_expected
.
to
have_many
(
:deployments
)
}
it
{
is_expected
.
to
have_many
(
:metrics_dashboard_annotations
)
}
it
{
is_expected
.
to
have_many
(
:alert_management_alerts
)
}
it
{
is_expected
.
to
have_one
(
:upcoming_deployment
)
}
it
{
is_expected
.
to
have_one
(
:latest_opened_most_severe_alert
)
}
it
{
is_expected
.
to
delegate_method
(
:stop_action
).
to
(
:last_deployment
)
}
...
...
@@ -723,6 +724,22 @@ RSpec.describe Environment, :use_clean_rails_memory_store_caching do
end
end
describe
'#upcoming_deployment'
do
subject
{
environment
.
upcoming_deployment
}
context
'when environment has a successful deployment'
do
let!
(
:deployment
)
{
create
(
:deployment
,
:success
,
environment:
environment
,
project:
project
)
}
it
{
is_expected
.
to
be_nil
}
end
context
'when environment has a running deployment'
do
let!
(
:deployment
)
{
create
(
:deployment
,
:running
,
environment:
environment
,
project:
project
)
}
it
{
is_expected
.
to
eq
(
deployment
)
}
end
end
describe
'#has_terminals?'
do
subject
{
environment
.
has_terminals?
}
...
...
spec/serializers/environment_entity_spec.rb
View file @
0527bfcd
...
...
@@ -7,15 +7,20 @@ RSpec.describe EnvironmentEntity do
let
(
:request
)
{
double
(
'request'
)
}
let
(
:entity
)
do
described_class
.
new
(
environment
,
request:
spy
(
'request'
)
)
described_class
.
new
(
environment
,
request:
request
)
end
let_it_be
(
:user
)
{
create
(
:user
)
}
let_it_be
(
:project
)
{
create
(
:project
)
}
let_it_be
(
:environment
)
{
create
(
:environment
,
project:
project
)
}
let_it_be
(
:project
)
{
create
(
:project
,
:repository
)
}
let_it_be
(
:environment
,
refind:
true
)
{
create
(
:environment
,
project:
project
)
}
before_all
do
project
.
add_developer
(
user
)
end
before
do
allow
(
entity
).
to
receive
(
:current_user
).
and_return
(
user
)
allow
(
request
).
to
receive
(
:current_user
).
and_return
(
user
)
allow
(
request
).
to
receive
(
:project
).
and_return
(
project
)
end
subject
{
entity
.
as_json
}
...
...
@@ -32,6 +37,51 @@ RSpec.describe EnvironmentEntity do
expect
(
subject
).
to
include
(
:folder_path
)
end
context
'when there is a successful deployment'
do
let!
(
:pipeline
)
{
create
(
:ci_pipeline
,
:success
,
project:
project
)
}
let!
(
:deployable
)
{
create
(
:ci_build
,
:success
,
project:
project
,
pipeline:
pipeline
)
}
let!
(
:deployment
)
{
create
(
:deployment
,
:success
,
project:
project
,
environment:
environment
,
deployable:
deployable
)
}
it
'exposes it as the latest deployment'
do
expect
(
subject
[
:last_deployment
][
:sha
]).
to
eq
(
deployment
.
sha
)
end
it
'does not expose it as an upcoming deployment'
do
expect
(
subject
[
:upcoming_deployment
]).
to
be_nil
end
context
'when the deployment pipeline has the other manual job'
do
let!
(
:manual_job
)
{
create
(
:ci_build
,
:manual
,
name:
'stop-review'
,
project:
project
,
pipeline:
pipeline
)
}
it
'exposes the manual job in the latest deployment'
do
expect
(
subject
[
:last_deployment
][
:manual_actions
].
first
[
:name
])
.
to
eq
(
manual_job
.
name
)
end
end
end
context
'when there is a running deployment'
do
let!
(
:pipeline
)
{
create
(
:ci_pipeline
,
:running
,
project:
project
)
}
let!
(
:deployable
)
{
create
(
:ci_build
,
:running
,
project:
project
,
pipeline:
pipeline
)
}
let!
(
:deployment
)
{
create
(
:deployment
,
:running
,
project:
project
,
environment:
environment
,
deployable:
deployable
)
}
it
'does not expose it as the latest deployment'
do
expect
(
subject
[
:last_deployment
]).
to
be_nil
end
it
'exposes it as an upcoming deployment'
do
expect
(
subject
[
:upcoming_deployment
][
:sha
]).
to
eq
(
deployment
.
sha
)
end
context
'when the deployment pipeline has the other manual job'
do
let!
(
:manual_job
)
{
create
(
:ci_build
,
:manual
,
name:
'stop-review'
,
project:
project
,
pipeline:
pipeline
)
}
it
'does not expose the manual job in the latest deployment'
do
expect
(
subject
[
:upcoming_deployment
][
:manual_actions
]).
to
be_nil
end
end
end
context
'metrics disabled'
do
before
do
allow
(
environment
).
to
receive
(
:has_metrics?
).
and_return
(
false
)
...
...
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