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
e6ca39f1
Commit
e6ca39f1
authored
Nov 06, 2019
by
Jason Goodman
Committed by
Douglas Barbosa Alexandre
Nov 06, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Return last pipeline for environment dashboard
Add last_visible_pipeline method to Environment model
parent
398fef1c
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
155 additions
and
6 deletions
+155
-6
app/models/environment.rb
app/models/environment.rb
+4
-0
ee/app/models/ee/environment.rb
ee/app/models/ee/environment.rb
+0
-2
ee/app/serializers/dashboard_environment_entity.rb
ee/app/serializers/dashboard_environment_entity.rb
+4
-0
ee/spec/controllers/operations_controller_spec.rb
ee/spec/controllers/operations_controller_spec.rb
+47
-2
ee/spec/serializers/dashboard_environment_entity_spec.rb
ee/spec/serializers/dashboard_environment_entity_spec.rb
+2
-1
ee/spec/serializers/dashboard_environments_folder_entity_spec.rb
.../serializers/dashboard_environments_folder_entity_spec.rb
+2
-1
spec/factories/deployments.rb
spec/factories/deployments.rb
+4
-0
spec/models/environment_spec.rb
spec/models/environment_spec.rb
+92
-0
No files found.
app/models/environment.rb
View file @
e6ca39f1
...
@@ -10,7 +10,11 @@ class Environment < ApplicationRecord
...
@@ -10,7 +10,11 @@ class Environment < ApplicationRecord
has_many
:successful_deployments
,
->
{
success
},
class_name:
'Deployment'
has_many
:successful_deployments
,
->
{
success
},
class_name:
'Deployment'
has_one
:last_deployment
,
->
{
success
.
order
(
'deployments.id DESC'
)
},
class_name:
'Deployment'
has_one
:last_deployment
,
->
{
success
.
order
(
'deployments.id DESC'
)
},
class_name:
'Deployment'
has_one
:last_deployable
,
through: :last_deployment
,
source:
'deployable'
,
source_type:
'CommitStatus'
has_one
:last_pipeline
,
through: :last_deployable
,
source:
'pipeline'
has_one
:last_visible_deployment
,
->
{
visible
.
distinct_on_environment
},
class_name:
'Deployment'
has_one
:last_visible_deployment
,
->
{
visible
.
distinct_on_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'
before_validation
:nullify_external_url
before_validation
:nullify_external_url
before_validation
:generate_slug
,
if:
->
(
env
)
{
env
.
slug
.
blank?
}
before_validation
:generate_slug
,
if:
->
(
env
)
{
env
.
slug
.
blank?
}
...
...
ee/app/models/ee/environment.rb
View file @
e6ca39f1
...
@@ -9,8 +9,6 @@ module EE
...
@@ -9,8 +9,6 @@ module EE
prepended
do
prepended
do
has_many
:prometheus_alerts
,
inverse_of: :environment
has_many
:prometheus_alerts
,
inverse_of: :environment
has_many
:self_managed_prometheus_alert_events
,
inverse_of: :environment
has_many
:self_managed_prometheus_alert_events
,
inverse_of: :environment
has_one
:last_deployable
,
through: :last_deployment
,
source:
'deployable'
,
source_type:
'CommitStatus'
has_one
:last_pipeline
,
through: :last_deployable
,
source:
'pipeline'
# Returns environments where its latest deployment is to a cluster
# Returns environments where its latest deployment is to a cluster
scope
:deployed_to_cluster
,
->
(
cluster
)
do
scope
:deployed_to_cluster
,
->
(
cluster
)
do
...
...
ee/app/serializers/dashboard_environment_entity.rb
View file @
e6ca39f1
...
@@ -15,6 +15,10 @@ class DashboardEnvironmentEntity < Grape::Entity
...
@@ -15,6 +15,10 @@ class DashboardEnvironmentEntity < Grape::Entity
DeploymentEntity
.
represent
(
environment
.
last_visible_deployment
,
options
.
merge
(
request:
request_with_project
))
DeploymentEntity
.
represent
(
environment
.
last_visible_deployment
,
options
.
merge
(
request:
request_with_project
))
end
end
expose
:last_visible_pipeline
,
as: :last_pipeline
,
expose_nil:
false
do
|
environment
|
PipelineDetailsEntity
.
represent
(
environment
.
last_visible_pipeline
,
options
.
merge
(
request:
request_with_project
))
end
private
private
alias_method
:environment
,
:object
alias_method
:environment
,
:object
...
...
ee/spec/controllers/operations_controller_spec.rb
View file @
e6ca39f1
...
@@ -454,7 +454,7 @@ describe OperationsController do
...
@@ -454,7 +454,7 @@ describe OperationsController do
it
'returns the last deployment for an environment'
do
it
'returns the last deployment for an environment'
do
environment
=
create
(
:environment
,
project:
project
)
environment
=
create
(
:environment
,
project:
project
)
deployment
=
create
(
:deployment
,
project:
project
,
environment:
environment
,
status: :success
)
deployment
=
create
(
:deployment
,
:success
,
project:
project
,
environment:
environment
)
get
:environments_list
get
:environments_list
...
@@ -471,7 +471,7 @@ describe OperationsController do
...
@@ -471,7 +471,7 @@ describe OperationsController do
it
"returns the last deployment's deployable"
do
it
"returns the last deployment's deployable"
do
environment
=
create
(
:environment
,
project:
project
)
environment
=
create
(
:environment
,
project:
project
)
ci_build
=
create
(
:ci_build
,
project:
project
)
ci_build
=
create
(
:ci_build
,
project:
project
)
create
(
:deployment
,
project:
project
,
environment:
environment
,
deployable:
ci_build
,
status: :success
)
create
(
:deployment
,
:success
,
project:
project
,
environment:
environment
,
deployable:
ci_build
)
get
:environments_list
get
:environments_list
...
@@ -501,6 +501,51 @@ describe OperationsController do
...
@@ -501,6 +501,51 @@ describe OperationsController do
expect
(
last_deployment_json
[
'id'
]).
to
eq
(
deployment
.
id
)
expect
(
last_deployment_json
[
'id'
]).
to
eq
(
deployment
.
id
)
end
end
context
'with a pipeline'
do
let
(
:project
)
{
create
(
:project
,
:repository
)
}
let
(
:commit
)
{
project
.
commit
}
let
(
:environment
)
{
create
(
:environment
,
project:
project
)
}
before
do
project
.
add_developer
(
user
)
user
.
update!
(
ops_dashboard_projects:
[
project
])
end
it
'returns the last pipeline for an environment'
do
pipeline
=
create
(
:ci_pipeline
,
project:
project
,
user:
user
,
sha:
commit
.
sha
)
ci_build
=
create
(
:ci_build
,
project:
project
,
pipeline:
pipeline
)
create
(
:deployment
,
:success
,
project:
project
,
environment:
environment
,
deployable:
ci_build
,
sha:
commit
.
sha
)
get
:environments_list
expect
(
response
).
to
have_gitlab_http_status
(
:ok
)
expect
(
response
).
to
match_response_schema
(
'dashboard/operations/environments_list'
,
dir:
'ee'
)
project_json
=
json_response
[
'projects'
].
first
environment_json
=
project_json
[
'environments'
].
first
last_pipeline_json
=
environment_json
[
'last_pipeline'
]
expect
(
last_pipeline_json
[
'id'
]).
to
eq
(
pipeline
.
id
)
end
it
'returns the last pipeline details'
do
pipeline
=
create
(
:ci_pipeline
,
project:
project
,
user:
user
,
sha:
commit
.
sha
,
status: :canceled
)
ci_build
=
create
(
:ci_build
,
project:
project
,
pipeline:
pipeline
)
create
(
:deployment
,
:canceled
,
project:
project
,
environment:
environment
,
deployable:
ci_build
,
sha:
commit
.
sha
)
get
:environments_list
expect
(
response
).
to
have_gitlab_http_status
(
:ok
)
expect
(
response
).
to
match_response_schema
(
'dashboard/operations/environments_list'
,
dir:
'ee'
)
project_json
=
json_response
[
'projects'
].
first
environment_json
=
project_json
[
'environments'
].
first
last_pipeline_json
=
environment_json
[
'last_pipeline'
]
expect
(
last_pipeline_json
.
dig
(
'details'
,
'status'
,
'group'
)).
to
eq
(
'canceled'
)
end
end
end
end
end
end
end
end
...
...
ee/spec/serializers/dashboard_environment_entity_spec.rb
View file @
e6ca39f1
...
@@ -12,7 +12,8 @@ describe DashboardEnvironmentEntity do
...
@@ -12,7 +12,8 @@ describe DashboardEnvironmentEntity do
result
=
described_class
.
new
(
environment
,
request:
request
).
as_json
result
=
described_class
.
new
(
environment
,
request:
request
).
as_json
expect
(
result
.
keys
.
sort
).
to
eq
([
:environment_path
,
:external_url
,
:id
,
:last_deployment
,
:name
])
expect
(
result
.
keys
.
sort
).
to
eq
([
:environment_path
,
:external_url
,
:id
,
:last_deployment
,
:last_pipeline
,
:name
])
end
end
end
end
end
end
ee/spec/serializers/dashboard_environments_folder_entity_spec.rb
View file @
e6ca39f1
...
@@ -14,7 +14,8 @@ describe DashboardEnvironmentsFolderEntity do
...
@@ -14,7 +14,8 @@ describe DashboardEnvironmentsFolderEntity do
result
=
described_class
.
new
(
environment_folder
,
request:
request
).
as_json
result
=
described_class
.
new
(
environment_folder
,
request:
request
).
as_json
expect
(
result
.
keys
.
sort
).
to
eq
([
:environment_path
,
:external_url
,
:id
,
:last_deployment
,
:name
,
:size
,
:within_folder
])
expect
(
result
.
keys
.
sort
).
to
eq
([
:environment_path
,
:external_url
,
:id
,
:last_deployment
,
:last_pipeline
,
:name
,
:size
,
:within_folder
])
end
end
end
end
end
end
spec/factories/deployments.rb
View file @
e6ca39f1
...
@@ -51,6 +51,10 @@ FactoryBot.define do
...
@@ -51,6 +51,10 @@ FactoryBot.define do
finished_at
{
Time
.
now
}
finished_at
{
Time
.
now
}
end
end
trait
:created
do
status
{
:created
}
end
# This trait hooks the state maechine's events
# This trait hooks the state maechine's events
trait
:succeed
do
trait
:succeed
do
after
(
:create
)
do
|
deployment
,
evaluator
|
after
(
:create
)
do
|
deployment
,
evaluator
|
...
...
spec/models/environment_spec.rb
View file @
e6ca39f1
...
@@ -5,6 +5,7 @@ require 'spec_helper'
...
@@ -5,6 +5,7 @@ require 'spec_helper'
describe
Environment
,
:use_clean_rails_memory_store_caching
do
describe
Environment
,
:use_clean_rails_memory_store_caching
do
include
ReactiveCachingHelpers
include
ReactiveCachingHelpers
using
RSpec
::
Parameterized
::
TableSyntax
using
RSpec
::
Parameterized
::
TableSyntax
include
RepoHelpers
let
(
:project
)
{
create
(
:project
,
:stubbed_repository
)
}
let
(
:project
)
{
create
(
:project
,
:stubbed_repository
)
}
subject
(
:environment
)
{
create
(
:environment
,
project:
project
)
}
subject
(
:environment
)
{
create
(
:environment
,
project:
project
)
}
...
@@ -505,6 +506,14 @@ describe Environment, :use_clean_rails_memory_store_caching do
...
@@ -505,6 +506,14 @@ describe Environment, :use_clean_rails_memory_store_caching do
end
end
end
end
context
'when there is a deployment record with failed status'
do
let!
(
:deployment
)
{
create
(
:deployment
,
:failed
,
environment:
environment
)
}
it
'returns the previous deployment'
do
is_expected
.
to
eq
(
previous_deployment
)
end
end
context
'when there is a deployment record with success status'
do
context
'when there is a deployment record with success status'
do
let!
(
:deployment
)
{
create
(
:deployment
,
:success
,
environment:
environment
)
}
let!
(
:deployment
)
{
create
(
:deployment
,
:success
,
environment:
environment
)
}
...
@@ -557,6 +566,89 @@ describe Environment, :use_clean_rails_memory_store_caching do
...
@@ -557,6 +566,89 @@ describe Environment, :use_clean_rails_memory_store_caching do
end
end
end
end
describe
'#last_visible_pipeline'
do
let
(
:user
)
{
create
(
:user
)
}
let_it_be
(
:project
)
{
create
(
:project
,
:repository
)
}
let
(
:environment
)
{
create
(
:environment
,
project:
project
)
}
let
(
:commit
)
{
project
.
commit
}
let
(
:success_pipeline
)
do
create
(
:ci_pipeline
,
:success
,
project:
project
,
user:
user
,
sha:
commit
.
sha
)
end
let
(
:failed_pipeline
)
do
create
(
:ci_pipeline
,
:failed
,
project:
project
,
user:
user
,
sha:
commit
.
sha
)
end
it
'uses the last deployment even if it failed'
do
pipeline
=
create
(
:ci_pipeline
,
project:
project
,
user:
user
,
sha:
commit
.
sha
)
ci_build
=
create
(
:ci_build
,
project:
project
,
pipeline:
pipeline
)
create
(
:deployment
,
:failed
,
project:
project
,
environment:
environment
,
deployable:
ci_build
,
sha:
commit
.
sha
)
last_pipeline
=
environment
.
last_visible_pipeline
expect
(
last_pipeline
).
to
eq
(
pipeline
)
end
it
'returns nil if there is no deployment'
do
create
(
:ci_build
,
project:
project
,
pipeline:
success_pipeline
)
expect
(
environment
.
last_visible_pipeline
).
to
be_nil
end
it
'does not return an invisible pipeline'
do
failed_pipeline
=
create
(
:ci_pipeline
,
project:
project
,
user:
user
,
sha:
commit
.
sha
)
ci_build_a
=
create
(
:ci_build
,
project:
project
,
pipeline:
failed_pipeline
)
create
(
:deployment
,
:failed
,
project:
project
,
environment:
environment
,
deployable:
ci_build_a
,
sha:
commit
.
sha
)
pipeline
=
create
(
:ci_pipeline
,
project:
project
,
user:
user
,
sha:
commit
.
sha
)
ci_build_b
=
create
(
:ci_build
,
project:
project
,
pipeline:
pipeline
)
create
(
:deployment
,
:created
,
project:
project
,
environment:
environment
,
deployable:
ci_build_b
,
sha:
commit
.
sha
)
last_pipeline
=
environment
.
last_visible_pipeline
expect
(
last_pipeline
).
to
eq
(
failed_pipeline
)
end
context
'for the environment'
do
it
'returns the last pipeline'
do
pipeline
=
create
(
:ci_pipeline
,
project:
project
,
user:
user
,
sha:
commit
.
sha
)
ci_build
=
create
(
:ci_build
,
project:
project
,
pipeline:
pipeline
)
create
(
:deployment
,
:success
,
project:
project
,
environment:
environment
,
deployable:
ci_build
,
sha:
commit
.
sha
)
last_pipeline
=
environment
.
last_visible_pipeline
expect
(
last_pipeline
).
to
eq
(
pipeline
)
end
context
'with multiple deployments'
do
it
'returns the last pipeline'
do
pipeline_a
=
create
(
:ci_pipeline
,
project:
project
,
user:
user
)
pipeline_b
=
create
(
:ci_pipeline
,
project:
project
,
user:
user
)
ci_build_a
=
create
(
:ci_build
,
project:
project
,
pipeline:
pipeline_a
)
ci_build_b
=
create
(
:ci_build
,
project:
project
,
pipeline:
pipeline_b
)
create
(
:deployment
,
:success
,
project:
project
,
environment:
environment
,
deployable:
ci_build_a
)
create
(
:deployment
,
:success
,
project:
project
,
environment:
environment
,
deployable:
ci_build_b
)
last_pipeline
=
environment
.
last_visible_pipeline
expect
(
last_pipeline
).
to
eq
(
pipeline_b
)
end
end
context
'with multiple pipelines'
do
it
'returns the last pipeline'
do
create
(
:ci_build
,
project:
project
,
pipeline:
success_pipeline
)
ci_build_b
=
create
(
:ci_build
,
project:
project
,
pipeline:
failed_pipeline
)
create
(
:deployment
,
:failed
,
project:
project
,
environment:
environment
,
deployable:
ci_build_b
,
sha:
commit
.
sha
)
last_pipeline
=
environment
.
last_visible_pipeline
expect
(
last_pipeline
).
to
eq
(
failed_pipeline
)
end
end
end
end
describe
'#has_terminals?'
do
describe
'#has_terminals?'
do
subject
{
environment
.
has_terminals?
}
subject
{
environment
.
has_terminals?
}
...
...
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