2017-06-07 05:36:41 -04:00
|
|
|
class JobEntity < Grape::Entity
|
2016-11-03 07:54:10 -04:00
|
|
|
include RequestAwareEntity
|
|
|
|
|
|
|
|
expose :id
|
|
|
|
expose :name
|
|
|
|
|
2016-11-17 10:08:05 -05:00
|
|
|
expose :build_path do |build|
|
2017-06-07 05:36:41 -04:00
|
|
|
build.target_url || path_to(:namespace_project_job, build)
|
2016-11-03 07:54:10 -04:00
|
|
|
end
|
|
|
|
|
2017-06-12 05:20:19 -04:00
|
|
|
expose :retry_path, if: -> (*) { retryable? } do |build|
|
2017-06-02 14:32:37 -04:00
|
|
|
path_to(:retry_namespace_project_job, build)
|
2016-11-03 08:35:57 -04:00
|
|
|
end
|
|
|
|
|
2017-06-12 05:20:19 -04:00
|
|
|
expose :cancel_path, if: -> (*) { cancelable? } do |build|
|
|
|
|
path_to(:cancel_namespace_project_job, build)
|
|
|
|
end
|
|
|
|
|
2017-05-03 06:32:39 -04:00
|
|
|
expose :play_path, if: -> (*) { playable? } do |build|
|
2017-05-16 07:41:15 -04:00
|
|
|
path_to(:play_namespace_project_job, build)
|
2016-11-03 08:35:57 -04:00
|
|
|
end
|
|
|
|
|
2017-03-17 12:25:17 -04:00
|
|
|
expose :playable?, as: :playable
|
2016-11-29 05:57:16 -05:00
|
|
|
expose :created_at
|
|
|
|
expose :updated_at
|
2017-03-10 10:16:48 -05:00
|
|
|
expose :detailed_status, as: :status, with: StatusEntity
|
2016-11-29 05:57:16 -05:00
|
|
|
|
2016-11-03 08:35:57 -04:00
|
|
|
private
|
|
|
|
|
2017-03-03 01:59:25 -05:00
|
|
|
alias_method :build, :object
|
|
|
|
|
2017-06-12 05:20:19 -04:00
|
|
|
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-04-06 06:58:13 -04:00
|
|
|
def playable?
|
2017-05-09 00:15:34 -04:00
|
|
|
build.playable? && can?(request.current_user, :update_build, build)
|
2016-11-03 07:54:10 -04:00
|
|
|
end
|
2017-03-03 01:59:25 -05:00
|
|
|
|
|
|
|
def detailed_status
|
2017-05-09 00:15:34 -04:00
|
|
|
build.detailed_status(request.current_user)
|
2017-03-03 01:59:25 -05:00
|
|
|
end
|
2017-04-06 06:58:13 -04:00
|
|
|
|
|
|
|
def path_to(route, build)
|
2017-08-03 22:20:34 -04:00
|
|
|
send("#{route}_path", build.project.namespace, build.project, build) # rubocop:disable GitlabSecurity/PublicSend
|
2017-04-06 06:58:13 -04:00
|
|
|
end
|
2016-11-03 07:54:10 -04:00
|
|
|
end
|