2020-01-31 18:09:11 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module API
|
|
|
|
module Entities
|
|
|
|
class CommitDetail < Commit
|
2022-08-30 18:09:50 +00:00
|
|
|
include ::API::Helpers::Presentable
|
|
|
|
|
|
|
|
expose :stats, using: Entities::CommitStats, if: :include_stats
|
2022-11-03 12:11:20 +00:00
|
|
|
expose :status_for, as: :status, documentation: { type: 'string', example: 'success' }
|
|
|
|
expose :project_id, documentation: { type: 'integer', example: 1 }
|
2020-01-31 18:09:11 +00:00
|
|
|
|
2022-11-03 12:11:20 +00:00
|
|
|
expose :last_pipeline, documentation: { type: ::API::Entities::Ci::PipelineBasic.to_s } do |commit, options|
|
2020-06-26 18:09:03 +00:00
|
|
|
pipeline = commit.last_pipeline if can_read_pipeline?
|
2020-08-13 18:10:36 +00:00
|
|
|
::API::Entities::Ci::PipelineBasic.represent(pipeline, options)
|
2020-01-31 18:09:11 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def can_read_pipeline?
|
2020-06-26 18:09:03 +00:00
|
|
|
Ability.allowed?(options[:current_user], :read_pipeline, object.last_pipeline)
|
2020-01-31 18:09:11 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|