2018-07-19 18:43:13 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-11-10 14:32:23 +00:00
|
|
|
class PipelineEntity < Grape::Entity
|
|
|
|
include RequestAwareEntity
|
|
|
|
|
|
|
|
expose :id
|
2016-12-01 10:59:00 +00:00
|
|
|
expose :user, using: UserEntity
|
2017-05-09 04:15:34 +00:00
|
|
|
expose :active?, as: :active
|
2018-05-11 14:17:03 +00:00
|
|
|
|
|
|
|
# Coverage isn't always necessary (e.g. when displaying project pipelines in
|
|
|
|
# the UI). Instead of creating an entirely different entity we just allow the
|
|
|
|
# disabling of this specific field whenever necessary.
|
|
|
|
expose :coverage, unless: proc { options[:disable_coverage] }
|
2017-05-24 13:13:51 +00:00
|
|
|
expose :source
|
2016-11-10 20:16:54 +00:00
|
|
|
|
2017-05-26 08:31:42 +00:00
|
|
|
expose :created_at, :updated_at
|
|
|
|
|
2016-12-15 14:57:35 +00:00
|
|
|
expose :path do |pipeline|
|
2017-06-29 17:06:35 +00:00
|
|
|
project_pipeline_path(pipeline.project, pipeline)
|
2016-11-10 17:15:16 +00:00
|
|
|
end
|
2016-11-10 14:32:23 +00:00
|
|
|
|
2017-05-29 07:58:20 +00:00
|
|
|
expose :flags do
|
|
|
|
expose :latest?, as: :latest
|
|
|
|
expose :stuck?, as: :stuck
|
2017-09-06 13:14:21 +00:00
|
|
|
expose :auto_devops_source?, as: :auto_devops
|
2017-05-29 07:58:20 +00:00
|
|
|
expose :has_yaml_errors?, as: :yaml_errors
|
|
|
|
expose :can_retry?, as: :retryable
|
|
|
|
expose :can_cancel?, as: :cancelable
|
2017-10-03 11:02:48 +00:00
|
|
|
expose :failure_reason?, as: :failure_reason
|
2017-05-29 07:58:20 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
expose :details do
|
2018-09-11 17:13:24 +00:00
|
|
|
expose :detailed_status, as: :status, with: DetailedStatusEntity
|
2017-05-29 07:58:20 +00:00
|
|
|
expose :duration
|
|
|
|
expose :finished_at
|
|
|
|
end
|
|
|
|
|
2016-12-01 10:59:00 +00:00
|
|
|
expose :ref do
|
2016-11-10 14:32:23 +00:00
|
|
|
expose :name do |pipeline|
|
|
|
|
pipeline.ref
|
|
|
|
end
|
|
|
|
|
2016-12-21 13:26:47 +00:00
|
|
|
expose :path do |pipeline|
|
2017-01-20 11:44:31 +00:00
|
|
|
if pipeline.ref
|
2017-05-11 15:47:44 +00:00
|
|
|
project_ref_path(pipeline.project, pipeline.ref)
|
2017-01-20 11:44:31 +00:00
|
|
|
end
|
2016-11-10 14:32:23 +00:00
|
|
|
end
|
|
|
|
|
2016-12-21 13:26:47 +00:00
|
|
|
expose :tag?, as: :tag
|
|
|
|
expose :branch?, as: :branch
|
2016-11-10 14:32:23 +00:00
|
|
|
end
|
|
|
|
|
2016-12-01 10:59:00 +00:00
|
|
|
expose :commit, using: CommitEntity
|
2017-10-03 11:02:48 +00:00
|
|
|
expose :yaml_errors, if: -> (pipeline, _) { pipeline.has_yaml_errors? }
|
|
|
|
|
|
|
|
expose :failure_reason, if: -> (pipeline, _) { pipeline.failure_reason? } do |pipeline|
|
|
|
|
pipeline.present.failure_reason
|
|
|
|
end
|
2016-11-10 14:32:23 +00:00
|
|
|
|
2017-05-03 10:32:39 +00:00
|
|
|
expose :retry_path, if: -> (*) { can_retry? } do |pipeline|
|
2017-06-29 17:06:35 +00:00
|
|
|
retry_project_pipeline_path(pipeline.project, pipeline)
|
2016-11-10 14:32:23 +00:00
|
|
|
end
|
|
|
|
|
2017-05-03 10:32:39 +00:00
|
|
|
expose :cancel_path, if: -> (*) { can_cancel? } do |pipeline|
|
2017-06-29 17:06:35 +00:00
|
|
|
cancel_project_pipeline_path(pipeline.project, pipeline)
|
2016-11-10 20:16:54 +00:00
|
|
|
end
|
|
|
|
|
2016-12-21 13:26:47 +00:00
|
|
|
private
|
|
|
|
|
|
|
|
alias_method :pipeline, :object
|
|
|
|
|
|
|
|
def can_retry?
|
2017-05-09 04:15:34 +00:00
|
|
|
can?(request.current_user, :update_pipeline, pipeline) &&
|
2017-04-06 12:31:38 +00:00
|
|
|
pipeline.retryable?
|
2016-12-21 13:26:47 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def can_cancel?
|
2017-05-09 04:15:34 +00:00
|
|
|
can?(request.current_user, :update_pipeline, pipeline) &&
|
2017-04-06 12:31:38 +00:00
|
|
|
pipeline.cancelable?
|
2016-12-21 13:26:47 +00:00
|
|
|
end
|
2017-03-03 06:59:25 +00:00
|
|
|
|
|
|
|
def detailed_status
|
2017-05-09 04:15:34 +00:00
|
|
|
pipeline.detailed_status(request.current_user)
|
2017-03-03 06:59:25 +00:00
|
|
|
end
|
2016-11-10 14:32:23 +00:00
|
|
|
end
|