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

74 lines
1.6 KiB
Ruby
Raw Normal View History

2018-11-18 11:00:15 +05:30
# frozen_string_literal: true
2017-09-10 17:25:29 +05:30
class JobEntity < Grape::Entity
2017-08-17 22:00:37 +05:30
include RequestAwareEntity
expose :id
expose :name
2018-03-17 18:26:18 +05:30
expose :started?, as: :started
2017-08-17 22:00:37 +05:30
expose :build_path do |build|
2017-09-10 17:25:29 +05:30
build.target_url || path_to(:namespace_project_job, build)
2017-08-17 22:00:37 +05:30
end
2017-09-10 17:25:29 +05:30
expose :retry_path, if: -> (*) { retryable? } do |build|
path_to(:retry_namespace_project_job, build)
end
expose :cancel_path, if: -> (*) { cancelable? } do |build|
path_to(:cancel_namespace_project_job, build)
2017-08-17 22:00:37 +05:30
end
expose :play_path, if: -> (*) { playable? } do |build|
2017-09-10 17:25:29 +05:30
path_to(:play_namespace_project_job, build)
2017-08-17 22:00:37 +05:30
end
expose :playable?, as: :playable
expose :created_at
expose :updated_at
expose :detailed_status, as: :status, with: StatusEntity
2018-11-08 19:23:39 +05:30
expose :callout_message, if: -> (*) { failed? && !build.script_failure? }
2018-10-15 14:42:47 +05:30
expose :recoverable, if: -> (*) { failed? }
2017-08-17 22:00:37 +05:30
private
alias_method :build, :object
2017-09-10 17:25:29 +05:30
def cancelable?
build.cancelable? && can?(request.current_user, :update_build, build)
end
def retryable?
build.retryable? && can?(request.current_user, :update_build, build)
end
2017-08-17 22:00:37 +05:30
def playable?
build.playable? && can?(request.current_user, :update_build, build)
end
def detailed_status
build.detailed_status(request.current_user)
end
def path_to(route, build)
2018-03-17 18:26:18 +05:30
send("#{route}_path", build.project.namespace, build.project, build) # rubocop:disable GitlabSecurity/PublicSend
2017-08-17 22:00:37 +05:30
end
2018-10-15 14:42:47 +05:30
def failed?
build.failed?
end
def callout_message
build_presenter.callout_failure_message
end
def recoverable
build_presenter.recoverable?
end
def build_presenter
@build_presenter ||= build.present
end
2017-08-17 22:00:37 +05:30
end