debian-mirror-gitlab/lib/api/resource_state_events.rb

54 lines
2.1 KiB
Ruby
Raw Normal View History

2020-07-28 23:09:34 +05:30
# frozen_string_literal: true
module API
2021-01-03 14:25:43 +05:30
class ResourceStateEvents < ::API::Base
2020-07-28 23:09:34 +05:30
include PaginationParams
helpers ::API::Helpers::NotesHelpers
before { authenticate! }
2022-10-11 01:57:18 +05:30
Helpers::ResourceEventsHelpers.eventable_types.each do |eventable_type, details|
parent_type = eventable_type.parent_class.to_s.underscore
eventables_str = eventable_type.to_s.underscore.pluralize
human_eventable_str = eventable_type.to_s.underscore.humanize.downcase
feature_category = details[:feature_category]
2020-07-28 23:09:34 +05:30
params do
2022-10-11 01:57:18 +05:30
requires :id, type: String, desc: "The ID of a #{parent_type}"
2020-07-28 23:09:34 +05:30
end
2022-10-11 01:57:18 +05:30
resource parent_type.pluralize.to_sym, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do
desc "Get a list of #{human_eventable_str} resource state events" do
2020-07-28 23:09:34 +05:30
success Entities::ResourceStateEvent
end
params do
2022-10-11 01:57:18 +05:30
requires :eventable_id, types: Integer, desc: "The #{details[:id_field]} of the #{human_eventable_str}"
2020-07-28 23:09:34 +05:30
use :pagination
end
2022-10-11 01:57:18 +05:30
get ":id/#{eventables_str}/:eventable_id/resource_state_events", feature_category: feature_category, urgency: :low do
eventable = find_noteable(eventable_type, params[:eventable_id])
2020-07-28 23:09:34 +05:30
events = ResourceStateEventFinder.new(current_user, eventable).execute
present paginate(events), with: Entities::ResourceStateEvent
end
2022-10-11 01:57:18 +05:30
desc "Get a single #{human_eventable_str} resource state event" do
2020-07-28 23:09:34 +05:30
success Entities::ResourceStateEvent
end
params do
2022-10-11 01:57:18 +05:30
requires :eventable_id, types: Integer, desc: "The #{details[:id_field]} of the #{human_eventable_str}"
2020-07-28 23:09:34 +05:30
requires :event_id, type: Integer, desc: 'The ID of a resource state event'
end
2022-10-11 01:57:18 +05:30
get ":id/#{eventables_str}/:eventable_id/resource_state_events/:event_id", feature_category: feature_category do
eventable = find_noteable(eventable_type, params[:eventable_id])
2020-07-28 23:09:34 +05:30
event = ResourceStateEventFinder.new(current_user, eventable).find(params[:event_id])
present event, with: Entities::ResourceStateEvent
end
end
end
end
end