debian-mirror-gitlab/app/serializers/deployment_entity.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

79 lines
2.3 KiB
Ruby
Raw Normal View History

2018-11-18 11:00:15 +05:30
# frozen_string_literal: true
2017-08-17 22:00:37 +05:30
class DeploymentEntity < Grape::Entity
include RequestAwareEntity
expose :id
expose :iid
expose :sha
expose :ref do
expose :name do |deployment|
deployment.ref
end
expose :ref_path do |deployment|
2017-09-10 17:25:29 +05:30
project_tree_path(deployment.project, id: deployment.ref)
2017-08-17 22:00:37 +05:30
end
end
2021-01-03 14:25:43 +05:30
expose :status
2017-08-17 22:00:37 +05:30
expose :created_at
2019-12-04 20:38:33 +05:30
expose :deployed_at
2017-08-17 22:00:37 +05:30
expose :tag
expose :last?
2022-01-26 12:08:38 +05:30
expose :last?, as: :is_last
2022-06-21 17:19:12 +05:30
expose :tier_in_yaml
2022-01-26 12:08:38 +05:30
2019-12-04 20:38:33 +05:30
expose :deployed_by, as: :user, using: UserEntity
2019-09-04 21:01:54 +05:30
2019-12-04 20:38:33 +05:30
expose :deployable, if: -> (deployment) { deployment.deployable.present? } do |deployment, opts|
2019-09-04 21:01:54 +05:30
deployment.deployable.yield_self do |deployable|
if include_details?
2022-01-26 12:08:38 +05:30
Ci::JobEntity.represent(deployable, opts)
2019-09-04 21:01:54 +05:30
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? }
2022-01-26 12:08:38 +05:30
expose :manual_actions, using: Ci::JobEntity, if: -> (*) { include_details? && can_create_deployment? }
expose :scheduled_actions, using: Ci::JobEntity, if: -> (*) { include_details? && can_create_deployment? }
2021-06-08 01:23:25 +05:30
expose :playable_build, if: -> (deployment) { include_details? && can_create_deployment? && deployment.playable_build } do |deployment, options|
2022-01-26 12:08:38 +05:30
Ci::JobEntity.represent(deployment.playable_build, options.merge(only: [:play_path, :retry_path]))
2020-01-01 13:55:28 +05:30
end
2019-03-02 22:35:43 +05:30
2020-03-13 15:44:24 +05:30
expose :cluster do |deployment, options|
# Until data is copied over from deployments.cluster_id, this entity must represent Deployment instead of DeploymentCluster
# https://gitlab.com/gitlab-org/gitlab/issues/202628
DeploymentClusterEntity.represent(deployment, options) unless deployment.cluster.nil?
end
2019-12-04 20:38:33 +05:30
2019-03-02 22:35:43 +05:30
private
2019-09-04 21:01:54 +05:30
def include_details?
options.fetch(:deployment_details, true)
end
2019-03-02 22:35:43 +05:30
def can_create_deployment?
2020-01-01 13:55:28 +05:30
can?(request.current_user, :create_deployment, project)
2019-03-02 22:35:43 +05:30
end
2019-09-04 21:01:54 +05:30
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.
#
2020-01-01 13:55:28 +05:30
can?(request.current_user, :read_build, project)
end
def project
request.try(:project) || options[:project]
2019-09-04 21:01:54 +05:30
end
2017-08-17 22:00:37 +05:30
end
2022-05-07 20:08:51 +05:30
DeploymentEntity.prepend_mod