summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShinya Maeda <shinya@gitlab.com>2018-10-16 16:27:26 +0900
committerShinya Maeda <shinya@gitlab.com>2018-10-17 14:36:40 +0900
commitfa13105707c2890421ff971db84ba5575a55442f (patch)
tree0629348f8233d3444687b4d3d7403518cc04b103
parentee18fef70e81ad7f618b85b39cb8e6b5c64f59f1 (diff)
downloadgitlab-ce-fa13105707c2890421ff971db84ba5575a55442f.tar.gz
Use deployment status in job log page
-rw-r--r--app/models/ci/build.rb22
-rw-r--r--app/models/deployment.rb6
-rw-r--r--app/models/environment.rb1
-rw-r--r--app/serializers/build_details_entity.rb12
-rw-r--r--app/serializers/detailed_status_entity.rb6
-rw-r--r--lib/gitlab/ci/status/core.rb4
-rw-r--r--lib/gitlab/ci/status/deployment/canceled.rb17
-rw-r--r--lib/gitlab/ci/status/deployment/common.rb25
-rw-r--r--lib/gitlab/ci/status/deployment/created.rb25
-rw-r--r--lib/gitlab/ci/status/deployment/factory.rb25
-rw-r--r--lib/gitlab/ci/status/deployment/failed.rb17
-rw-r--r--lib/gitlab/ci/status/deployment/manual.rb17
-rw-r--r--lib/gitlab/ci/status/deployment/pending.rb17
-rw-r--r--lib/gitlab/ci/status/deployment/running.rb17
-rw-r--r--lib/gitlab/ci/status/deployment/scheduled.rb17
-rw-r--r--lib/gitlab/ci/status/deployment/skipped.rb17
-rw-r--r--lib/gitlab/ci/status/deployment/success.rb25
17 files changed, 257 insertions, 13 deletions
diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb
index cdfe8175a42..c5e6e0d46d2 100644
--- a/app/models/ci/build.rb
+++ b/app/models/ci/build.rb
@@ -701,17 +701,21 @@ module Ci
end
# Virtual deployment status depending on the environment status.
- def deployment_status
- return nil unless starts_environment?
+ # def deployment_status
+ # last_deployment.detailed_status
+ # end
- if success?
- return successful_deployment_status
- elsif complete? && !success?
- return :failed
- end
+ # def deployment_status
+ # return nil unless starts_environment?
- :creating
- end
+ # if success?
+ # return successful_deployment_status
+ # elsif complete? && !success?
+ # return :failed
+ # end
+
+ # :creating
+ # end
private
diff --git a/app/models/deployment.rb b/app/models/deployment.rb
index a5ac0f34aea..60abc15c056 100644
--- a/app/models/deployment.rb
+++ b/app/models/deployment.rb
@@ -86,6 +86,12 @@ class Deployment < ActiveRecord::Base
super
end
+ def detailed_status(current_user)
+ Gitlab::Ci::Status::Deployment::Factory
+ .new(self, current_user)
+ .fabricate!
+ end
+
def self.last_for_environment(environment)
ids = self
.for_environment(environment)
diff --git a/app/models/environment.rb b/app/models/environment.rb
index 0816c395185..2cca4a8efad 100644
--- a/app/models/environment.rb
+++ b/app/models/environment.rb
@@ -11,6 +11,7 @@ class Environment < ActiveRecord::Base
has_many :deployments, dependent: :destroy # rubocop:disable Cop/ActiveRecordDependent
has_one :last_deployment, -> { order('deployments.id DESC') }, class_name: 'Deployment'
+ has_one :last_successful_deployment, -> { success.order('deployments.id DESC') }, class_name: 'Deployment'
before_validation :nullify_external_url
before_validation :generate_slug, if: ->(env) { env.slug.blank? }
diff --git a/app/serializers/build_details_entity.rb b/app/serializers/build_details_entity.rb
index 066a5b1885c..7144617d3b7 100644
--- a/app/serializers/build_details_entity.rb
+++ b/app/serializers/build_details_entity.rb
@@ -9,12 +9,16 @@ class BuildDetailsEntity < JobEntity
expose :runner, using: RunnerEntity
expose :pipeline, using: PipelineEntity
- expose :deployment_status, if: -> (*) { build.starts_environment? } do
- expose :deployment_status, as: :status
-
- expose :persisted_environment, as: :environment, with: EnvironmentEntity
+ expose :deployment_status, with: DetailedStatusEntity do |build|
+ build.last_deployment.detailed_status
end
+ # expose :deployment_status, if: -> (*) { build.starts_environment? } do
+ # expose :deployment_status, as: :status
+
+ # expose :persisted_environment, as: :environment, with: EnvironmentEntity
+ # end
+
expose :metadata, using: BuildMetadataEntity
expose :artifact, if: -> (*) { can?(current_user, :read_build, build) } do
diff --git a/app/serializers/detailed_status_entity.rb b/app/serializers/detailed_status_entity.rb
index da994d78286..76cebc4bb9a 100644
--- a/app/serializers/detailed_status_entity.rb
+++ b/app/serializers/detailed_status_entity.rb
@@ -32,4 +32,10 @@ class DetailedStatusEntity < Grape::Entity
expose :action_method, as: :method
expose :action_button_title, as: :button_title
end
+
+ expose :deployment_status, if: -> (status, _) { status.has_deployment? } do
+ expose :environment_text
+ expose :environment_path
+ expose :deployment_path
+ end
end
diff --git a/lib/gitlab/ci/status/core.rb b/lib/gitlab/ci/status/core.rb
index 9d6a2f51c11..befde27cdf7 100644
--- a/lib/gitlab/ci/status/core.rb
+++ b/lib/gitlab/ci/status/core.rb
@@ -66,6 +66,10 @@ module Gitlab
raise NotImplementedError
end
+ def has_deployment?
+ false
+ end
+
# Hint that appears on all the pipeline graph tooltips and builds on the right sidebar in Job detail view
def status_tooltip
label
diff --git a/lib/gitlab/ci/status/deployment/canceled.rb b/lib/gitlab/ci/status/deployment/canceled.rb
new file mode 100644
index 00000000000..d0693ae1a9c
--- /dev/null
+++ b/lib/gitlab/ci/status/deployment/canceled.rb
@@ -0,0 +1,17 @@
+module Gitlab
+ module Ci
+ module Status
+ module Deployment
+ class Canceled < Status::Extended
+ def environment_text
+ "This job was canceled to deploy to %{environmentLink}."
+ end
+
+ def self.matches?(deployment, user)
+ deployment.canceled?
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/lib/gitlab/ci/status/deployment/common.rb b/lib/gitlab/ci/status/deployment/common.rb
new file mode 100644
index 00000000000..a31acf490d1
--- /dev/null
+++ b/lib/gitlab/ci/status/deployment/common.rb
@@ -0,0 +1,25 @@
+module Gitlab
+ module Ci
+ module Status
+ module Deployment
+ module Common
+ def has_details?
+ can?(user, :read_deployment, subject)
+ end
+
+ def details_path
+ project_deployment_path(subject.project, subject)
+ end
+
+ def environment_path
+ project_environment_path(subject.project, subject.environment)
+ end
+
+ def has_deployment?
+ true
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/lib/gitlab/ci/status/deployment/created.rb b/lib/gitlab/ci/status/deployment/created.rb
new file mode 100644
index 00000000000..84611d6de62
--- /dev/null
+++ b/lib/gitlab/ci/status/deployment/created.rb
@@ -0,0 +1,25 @@
+module Gitlab
+ module Ci
+ module Status
+ module Deployment
+ class Created < Status::Extended
+ def environment_text
+ if subject.environment.deployments.any?
+ "This job will deploy to %{environmentLink} and overwrite the %{deploymentLink}."
+ else
+ "This job will deploy to %{environmentLink}."
+ end
+ end
+
+ def deployment_link
+ project_deployment_path(subject.project, subject.environment.last_successful_deployment)
+ end
+
+ def self.matches?(deployment, user)
+ deployment.created?
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/lib/gitlab/ci/status/deployment/factory.rb b/lib/gitlab/ci/status/deployment/factory.rb
new file mode 100644
index 00000000000..0b5ceaed986
--- /dev/null
+++ b/lib/gitlab/ci/status/deployment/factory.rb
@@ -0,0 +1,25 @@
+module Gitlab
+ module Ci
+ module Status
+ module Deployment
+ class Factory < Status::Factory
+ def self.extended_statuses
+ [[Status::Deployment::Canceled,
+ Status::Deployment::Created,
+ Status::Deployment::Failed,
+ Status::Deployment::Manual,
+ Status::Deployment::Pending,
+ Status::Deployment::Running,
+ Status::Deployment::Scheduled,
+ Status::Deployment::Skipped,
+ Status::Deployment::Success]]
+ end
+
+ def self.common_helpers
+ Status::Deployment::Common
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/lib/gitlab/ci/status/deployment/failed.rb b/lib/gitlab/ci/status/deployment/failed.rb
new file mode 100644
index 00000000000..7218a961c73
--- /dev/null
+++ b/lib/gitlab/ci/status/deployment/failed.rb
@@ -0,0 +1,17 @@
+module Gitlab
+ module Ci
+ module Status
+ module Deployment
+ class Failed < Status::Extended
+ def environment_text
+ "The deployment of this job to %{environmentLink} did not succeed."
+ end
+
+ def self.matches?(deployment, user)
+ deployment.failed?
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/lib/gitlab/ci/status/deployment/manual.rb b/lib/gitlab/ci/status/deployment/manual.rb
new file mode 100644
index 00000000000..0ee2a53e404
--- /dev/null
+++ b/lib/gitlab/ci/status/deployment/manual.rb
@@ -0,0 +1,17 @@
+module Gitlab
+ module Ci
+ module Status
+ module Deployment
+ class Manual < Status::Extended
+ def environment_text
+ "Please trigger the build to deploy to %{environmentLink}."
+ end
+
+ def self.matches?(deployment, user)
+ deployment.manual?
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/lib/gitlab/ci/status/deployment/pending.rb b/lib/gitlab/ci/status/deployment/pending.rb
new file mode 100644
index 00000000000..6b6baddbccb
--- /dev/null
+++ b/lib/gitlab/ci/status/deployment/pending.rb
@@ -0,0 +1,17 @@
+module Gitlab
+ module Ci
+ module Status
+ module Deployment
+ class Pending < Status::Extended
+ def environment_text
+ "This job deploys to %{environmentLink} soon."
+ end
+
+ def self.matches?(deployment, user)
+ deployment.pending?
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/lib/gitlab/ci/status/deployment/running.rb b/lib/gitlab/ci/status/deployment/running.rb
new file mode 100644
index 00000000000..1b9368c1b62
--- /dev/null
+++ b/lib/gitlab/ci/status/deployment/running.rb
@@ -0,0 +1,17 @@
+module Gitlab
+ module Ci
+ module Status
+ module Deployment
+ class Running < Status::Extended
+ def environment_text
+ "This job is deploying to %{environmentLink}."
+ end
+
+ def self.matches?(deployment, user)
+ deployment.running?
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/lib/gitlab/ci/status/deployment/scheduled.rb b/lib/gitlab/ci/status/deployment/scheduled.rb
new file mode 100644
index 00000000000..9c718c930cb
--- /dev/null
+++ b/lib/gitlab/ci/status/deployment/scheduled.rb
@@ -0,0 +1,17 @@
+module Gitlab
+ module Ci
+ module Status
+ module Deployment
+ class Scheduled < Status::Extended
+ def environment_text
+ "This job is scheduled to deploy to %{environmentLink}."
+ end
+
+ def self.matches?(deployment, user)
+ deployment.scheduled?
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/lib/gitlab/ci/status/deployment/skipped.rb b/lib/gitlab/ci/status/deployment/skipped.rb
new file mode 100644
index 00000000000..b610a26c491
--- /dev/null
+++ b/lib/gitlab/ci/status/deployment/skipped.rb
@@ -0,0 +1,17 @@
+module Gitlab
+ module Ci
+ module Status
+ module Deployment
+ class Skipped < Status::Extended
+ def environment_text
+ "This job was skipped and did not deploy to %{environmentLink}."
+ end
+
+ def self.matches?(deployment, user)
+ deployment.skipped?
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/lib/gitlab/ci/status/deployment/success.rb b/lib/gitlab/ci/status/deployment/success.rb
new file mode 100644
index 00000000000..2f9229147cb
--- /dev/null
+++ b/lib/gitlab/ci/status/deployment/success.rb
@@ -0,0 +1,25 @@
+module Gitlab
+ module Ci
+ module Status
+ module Deployment
+ class Success < Status::Extended
+ def environment_text
+ if subject.last?
+ "This job is the most recent deployment to %{environmentLink}."
+ else
+ "This job is an out-of-date deployment to %{environmentLink}. View the most recent deployment %{deploymentLink}."
+ end
+ end
+
+ def deploymentLink
+ project_deployment_path(subject.project, subject.environment.last_successful_deployment)
+ end
+
+ def self.matches?(deployment, user)
+ deployment.success?
+ end
+ end
+ end
+ end
+ end
+end