Skip to content
Snippets Groups Projects
Commit faeb32b9 authored by Shinya Maeda's avatar Shinya Maeda
Browse files

Virtual deployment status calculation

parent 75b6ed8d
No related branches found
No related tags found
No related merge requests found
Showing
with 200 additions and 5 deletions
Loading
Loading
@@ -116,6 +116,8 @@ module Ci
where("EXISTS (?)", matcher)
end
 
scope :with_environment, ->() { where("environment <> ''") }
mount_uploader :legacy_artifacts_file, LegacyArtifactUploader, mount_on: :artifacts_file
mount_uploader :legacy_artifacts_metadata, LegacyArtifactUploader, mount_on: :artifacts_metadata
 
Loading
Loading
@@ -327,6 +329,10 @@ module Ci
success? && !last_deployment.try(:last?)
end
 
def has_latest_deployment?
last_deployment.try(:last?)
end
def depends_on_builds
# Get builds of the same type
latest_builds = self.pipeline.builds.latest
Loading
Loading
Loading
Loading
@@ -614,6 +614,14 @@ module Ci
.fabricate!
end
 
def detailed_deployments_status(current_user)
builds.latest.with_environment.map do |deployable|
Gitlab::Ci::Status::Build::Factory
.new(deployable, current_user)
.fabricate!
end
end
def latest_builds_with_artifacts
# We purposely cast the builds to an Array here. Because we always use the
# rows if there are more than 0 this prevents us from having to run two
Loading
Loading
Loading
Loading
@@ -10,9 +10,9 @@ class BuildDetailsEntity < JobEntity
expose :pipeline, using: PipelineEntity
 
expose :deployment_status, if: -> (*) { build.has_environment? } do
expose :deployment_status, as: :status
expose :persisted_environment, as: :environment, with: EnvironmentEntity
expose :deployments_detail, with: DeploymentStatusEntity do |build|
detailed_status
end
end
 
expose :metadata, using: BuildMetadataEntity
Loading
Loading
# frozen_string_literal: true
class DeploymentStatusEntity < Grape::Entity
include RequestAwareEntity
expose :deployment_status, as: :status, if: -> (status, _) { status.has_deployments? }
expose :environment, with: EnvironmentEntity, if: -> (status, _) { status.has_deployments? }
end
Loading
Loading
@@ -8,7 +8,7 @@ class EnvironmentEntity < Grape::Entity
expose :state
expose :external_url
expose :environment_type
expose :last_deployment, using: DeploymentEntity
# expose :last_deployment, using: DeploymentEntity # TODO: Fix cycle reference
expose :stop_action_available?, as: :has_stop_action
 
expose :metrics_path, if: -> (environment, _) { environment.has_metrics? } do |environment|
Loading
Loading
Loading
Loading
@@ -33,6 +33,7 @@ class PipelineEntity < Grape::Entity
expose :detailed_status, as: :status, with: DetailedStatusEntity
expose :duration
expose :finished_at
expose :deployments_details, with: DeploymentStatusEntity
end
 
expose :ref do
Loading
Loading
@@ -82,4 +83,8 @@ class PipelineEntity < Grape::Entity
def detailed_status
pipeline.detailed_status(request.current_user)
end
def deployments_details
pipeline.detailed_deployments_status(request.current_user)
end
end
module Gitlab
module Ci
module Status
module Build
class DeployedFailed < Status::Extended
def deployment_status
:failed
end
def has_deployments?
true
end
def environment
subject.persisted_environment
end
def self.matches?(build, user)
build.has_environment? && build.failed?
end
end
end
end
end
end
module Gitlab
module Ci
module Status
module Build
class DeployedLatest < Status::Extended
def deployment_status
:last
end
def has_deployments?
true
end
def environment
subject.persisted_environment
end
def self.matches?(build, user)
build.has_environment? &&
build.success? &&
build.has_latest_deployment?
end
end
end
end
end
end
module Gitlab
module Ci
module Status
module Build
class DeployedOutdated < Status::Extended
def deployment_status
:out_of_date
end
def has_deployments?
true
end
def environment
subject.persisted_environment
end
def self.matches?(build, user)
build.has_environment? &&
build.success? &&
!build.has_latest_deployment?
end
end
end
end
end
end
module Gitlab
module Ci
module Status
module Build
class Deploying < Status::Extended
def deployment_status
:creating
end
def has_deployments?
true
end
def environment
subject.persisted_environment
end
def self.matches?(build, user)
build.has_environment? && build.running?
end
end
end
end
end
end
Loading
Loading
@@ -19,7 +19,13 @@ module Gitlab
Status::Build::Play,
Status::Build::Stop],
[Status::Build::Action],
[Status::Build::Retried]]
[Status::Build::Retried],
[Status::Build::WillDeploy,
Status::Build::ManualDeploy,
Status::Build::Deploying,
Status::Build::DeployedLatest,
Status::Build::DeployedOutdated,
Status::Build::DeployedFailed]]
end
 
def self.common_helpers
Loading
Loading
module Gitlab
module Ci
module Status
module Build
class ManualDeploy < Status::Extended
def deployment_status
:manual_deploy
end
def has_deployments?
true
end
def environment
subject.persisted_environment
end
def self.matches?(build, user)
build.has_environment? && (build.manual?)
end
end
end
end
end
end
module Gitlab
module Ci
module Status
module Build
class WillDeploy < Status::Extended
def deployment_status
:will_deploy
end
def has_deployments?
true
end
def environment
subject.persisted_environment
end
def self.matches?(build, user)
build.has_environment? && (build.created? || build.pending?)
end
end
end
end
end
end
Loading
Loading
@@ -66,6 +66,14 @@ module Gitlab
raise NotImplementedError
end
 
def has_deployments?
false
end
def environment
raise NotImplementedError
end
# Hint that appears on all the pipeline graph tooltips and builds on the right sidebar in Job detail view
def status_tooltip
label
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment