2020-05-24 23:13:21 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module API
|
2021-01-03 14:25:43 +05:30
|
|
|
class FreezePeriods < ::API::Base
|
2020-05-24 23:13:21 +05:30
|
|
|
include PaginationParams
|
|
|
|
|
2023-01-13 00:05:48 +05:30
|
|
|
freeze_periods_tags = %w[freeze_periods]
|
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
before { authenticate! }
|
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
feature_category :continuous_delivery
|
2022-07-16 23:28:13 +05:30
|
|
|
urgency :low
|
2021-01-29 00:20:46 +05:30
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
params do
|
2023-01-13 00:05:48 +05:30
|
|
|
requires :id, types: [String, Integer], desc: 'The ID or URL-encoded path of the project'
|
2020-05-24 23:13:21 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
resource :projects, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do
|
2023-01-13 00:05:48 +05:30
|
|
|
desc 'List freeze periods' do
|
|
|
|
detail 'Paginated list of Freeze Periods, sorted by created_at in ascending order. ' \
|
|
|
|
'This feature was introduced in GitLab 13.0.'
|
2020-05-24 23:13:21 +05:30
|
|
|
success Entities::FreezePeriod
|
2023-01-13 00:05:48 +05:30
|
|
|
failure [
|
|
|
|
{ code: 401, message: 'Unauthorized' },
|
|
|
|
{ code: 404, message: 'Not found' }
|
|
|
|
]
|
|
|
|
is_array true
|
|
|
|
tags freeze_periods_tags
|
2020-05-24 23:13:21 +05:30
|
|
|
end
|
|
|
|
params do
|
|
|
|
use :pagination
|
|
|
|
end
|
|
|
|
|
|
|
|
get ":id/freeze_periods" do
|
|
|
|
authorize! :read_freeze_period, user_project
|
|
|
|
|
2023-03-04 22:38:38 +05:30
|
|
|
freeze_periods = ::Ci::FreezePeriodsFinder.new(user_project, current_user).execute
|
2020-05-24 23:13:21 +05:30
|
|
|
|
|
|
|
present paginate(freeze_periods), with: Entities::FreezePeriod, current_user: current_user
|
|
|
|
end
|
|
|
|
|
2023-01-13 00:05:48 +05:30
|
|
|
desc 'Get a freeze period' do
|
|
|
|
detail 'Get a freeze period for the given `freeze_period_id`. This feature was introduced in GitLab 13.0.'
|
2020-05-24 23:13:21 +05:30
|
|
|
success Entities::FreezePeriod
|
2023-01-13 00:05:48 +05:30
|
|
|
failure [
|
|
|
|
{ code: 401, message: 'Unauthorized' },
|
|
|
|
{ code: 404, message: 'Not found' }
|
|
|
|
]
|
|
|
|
tags freeze_periods_tags
|
2020-05-24 23:13:21 +05:30
|
|
|
end
|
|
|
|
params do
|
2023-01-13 00:05:48 +05:30
|
|
|
requires :freeze_period_id, type: Integer, desc: 'The ID of the freeze period'
|
2020-05-24 23:13:21 +05:30
|
|
|
end
|
|
|
|
get ":id/freeze_periods/:freeze_period_id" do
|
|
|
|
authorize! :read_freeze_period, user_project
|
|
|
|
|
|
|
|
present freeze_period, with: Entities::FreezePeriod, current_user: current_user
|
|
|
|
end
|
|
|
|
|
2023-01-13 00:05:48 +05:30
|
|
|
desc 'Create a freeze period' do
|
|
|
|
detail 'Creates a freeze period. This feature was introduced in GitLab 13.0.'
|
2020-05-24 23:13:21 +05:30
|
|
|
success Entities::FreezePeriod
|
2023-01-13 00:05:48 +05:30
|
|
|
failure [
|
|
|
|
{ code: 400, message: 'Bad request' },
|
|
|
|
{ code: 401, message: 'Unauthorized' }
|
|
|
|
]
|
|
|
|
tags freeze_periods_tags
|
2020-05-24 23:13:21 +05:30
|
|
|
end
|
|
|
|
params do
|
2023-01-13 00:05:48 +05:30
|
|
|
requires :freeze_start, type: String, desc: 'Start of the freeze period in cron format.'
|
|
|
|
requires :freeze_end, type: String, desc: 'End of the freeze period in cron format'
|
|
|
|
optional :cron_timezone,
|
|
|
|
type: String,
|
|
|
|
desc: 'The time zone for the cron fields, defaults to UTC if not provided'
|
2020-05-24 23:13:21 +05:30
|
|
|
end
|
|
|
|
post ':id/freeze_periods' do
|
|
|
|
authorize! :create_freeze_period, user_project
|
|
|
|
|
|
|
|
freeze_period_params = declared(params, include_parent_namespaces: false)
|
|
|
|
|
|
|
|
freeze_period = user_project.freeze_periods.create(freeze_period_params)
|
|
|
|
|
|
|
|
if freeze_period.persisted?
|
|
|
|
present freeze_period, with: Entities::FreezePeriod
|
|
|
|
else
|
|
|
|
render_validation_error!(freeze_period)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
desc 'Update a freeze period' do
|
2023-01-13 00:05:48 +05:30
|
|
|
detail 'Updates a freeze period for the given `freeze_period_id`. This feature was introduced in GitLab 13.0.'
|
2020-05-24 23:13:21 +05:30
|
|
|
success Entities::FreezePeriod
|
2023-01-13 00:05:48 +05:30
|
|
|
failure [
|
|
|
|
{ code: 400, message: 'Bad request' },
|
|
|
|
{ code: 401, message: 'Unauthorized' }
|
|
|
|
]
|
|
|
|
tags freeze_periods_tags
|
2020-05-24 23:13:21 +05:30
|
|
|
end
|
|
|
|
params do
|
2023-01-13 00:05:48 +05:30
|
|
|
optional :freeze_start, type: String, desc: 'Start of the freeze period in cron format'
|
|
|
|
optional :freeze_end, type: String, desc: 'End of the freeze period in cron format'
|
|
|
|
optional :cron_timezone, type: String, desc: 'The time zone for the cron fields'
|
2020-05-24 23:13:21 +05:30
|
|
|
end
|
|
|
|
put ':id/freeze_periods/:freeze_period_id' do
|
|
|
|
authorize! :update_freeze_period, user_project
|
|
|
|
|
|
|
|
freeze_period_params = declared(params, include_parent_namespaces: false, include_missing: false)
|
|
|
|
|
|
|
|
if freeze_period.update(freeze_period_params)
|
|
|
|
present freeze_period, with: Entities::FreezePeriod
|
|
|
|
else
|
|
|
|
render_validation_error!(freeze_period)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
desc 'Delete a freeze period' do
|
2023-01-13 00:05:48 +05:30
|
|
|
detail 'Deletes a freeze period for the given `freeze_period_id`. This feature was introduced in GitLab 13.0.'
|
2020-05-24 23:13:21 +05:30
|
|
|
success Entities::FreezePeriod
|
2023-01-13 00:05:48 +05:30
|
|
|
failure [
|
|
|
|
{ code: 401, message: 'Unauthorized' }
|
|
|
|
]
|
|
|
|
tags freeze_periods_tags
|
2020-05-24 23:13:21 +05:30
|
|
|
end
|
|
|
|
params do
|
2023-01-13 00:05:48 +05:30
|
|
|
requires :freeze_period_id, type: Integer, desc: 'The ID of the freeze period'
|
2020-05-24 23:13:21 +05:30
|
|
|
end
|
|
|
|
delete ':id/freeze_periods/:freeze_period_id' do
|
|
|
|
authorize! :destroy_freeze_period, user_project
|
|
|
|
|
|
|
|
destroy_conditionally!(freeze_period)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
helpers do
|
|
|
|
def freeze_period
|
|
|
|
@freeze_period ||= user_project.freeze_periods.find(params[:freeze_period_id])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|