gitlab-org--gitlab-foss/lib/api/labels.rb

125 lines
4.1 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
2014-08-12 08:16:25 -04:00
module API
class Labels < Grape::API
include PaginationParams
helpers ::API::Helpers::LabelHelpers
2017-02-20 13:18:12 -05:00
2014-08-12 08:16:25 -04:00
before { authenticate! }
2016-10-24 08:05:33 -04:00
params do
requires :id, type: String, desc: 'The ID of a project'
end
resource :projects, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do
2016-10-24 08:05:33 -04:00
desc 'Get all labels of the project' do
2018-12-28 04:47:00 -05:00
success Entities::ProjectLabel
2016-10-24 08:05:33 -04:00
end
params do
optional :with_counts, type: Boolean, default: false,
desc: 'Include issue and merge request counts'
optional :include_ancestor_groups, type: Boolean, default: true,
desc: 'Include ancestor groups'
use :pagination
end
2014-08-12 08:16:25 -04:00
get ':id/labels' do
get_labels(user_project, Entities::ProjectLabel, include_ancestor_groups: params[:include_ancestor_groups])
2014-08-12 08:16:25 -04:00
end
desc 'Get a single label' do
detail 'This feature was added in GitLab 12.4.'
success Entities::ProjectLabel
end
params do
optional :include_ancestor_groups, type: Boolean, default: true,
desc: 'Include ancestor groups'
end
get ':id/labels/:name' do
get_label(user_project, Entities::ProjectLabel, include_ancestor_groups: params[:include_ancestor_groups])
end
2016-10-24 08:05:33 -04:00
desc 'Create a new label' do
2018-12-28 04:47:00 -05:00
success Entities::ProjectLabel
2016-10-24 08:05:33 -04:00
end
params do
2019-01-06 14:31:37 -05:00
use :label_create_params
optional :priority, type: Integer, desc: 'The priority of the label', allow_blank: true
2016-10-24 08:05:33 -04:00
end
2014-08-12 08:16:25 -04:00
post ':id/labels' do
2019-01-06 14:31:37 -05:00
create_label(user_project, Entities::ProjectLabel)
2014-08-12 08:16:25 -04:00
end
2014-08-13 06:23:51 -04:00
2016-10-24 08:05:33 -04:00
desc 'Update an existing label. At least one optional parameter is required.' do
detail 'This feature was deprecated in GitLab 12.4.'
2018-12-28 04:47:00 -05:00
success Entities::ProjectLabel
2016-10-24 08:05:33 -04:00
end
params do
optional :label_id, type: Integer, desc: 'The id of the label to be updated'
optional :name, type: String, desc: 'The name of the label to be updated'
use :project_label_update_params
exactly_one_of :label_id, :name
2016-10-24 08:05:33 -04:00
end
2014-08-13 06:23:51 -04:00
put ':id/labels' do
2019-01-06 14:31:37 -05:00
update_label(user_project, Entities::ProjectLabel)
end
2019-01-06 14:31:37 -05:00
desc 'Delete an existing label' do
detail 'This feature was deprecated in GitLab 12.4.'
2019-01-06 14:31:37 -05:00
success Entities::ProjectLabel
end
params do
optional :label_id, type: Integer, desc: 'The id of the label to be deleted'
optional :name, type: String, desc: 'The name of the label to be deleted'
exactly_one_of :label_id, :name
2019-01-06 14:31:37 -05:00
end
delete ':id/labels' do
delete_label(user_project)
2014-08-13 06:23:51 -04:00
end
desc 'Promote a label to a group label' do
detail 'This feature was added in GitLab 12.3 and deprecated in GitLab 12.4.'
success Entities::GroupLabel
end
params do
requires :name, type: String, desc: 'The name of the label to be promoted'
end
2019-02-14 05:40:28 -05:00
put ':id/labels/promote' do
promote_label(user_project)
end
desc 'Update an existing label. At least one optional parameter is required.' do
detail 'This feature was added in GitLab 12.4.'
success Entities::ProjectLabel
end
params do
requires :name, type: String, desc: 'The name or id of the label to be updated'
use :project_label_update_params
end
put ':id/labels/:name' do
update_label(user_project, Entities::ProjectLabel)
end
desc 'Delete an existing label' do
detail 'This feature was added in GitLab 12.4.'
success Entities::ProjectLabel
end
params do
requires :name, type: String, desc: 'The name or id of the label to be deleted'
end
delete ':id/labels/:name' do
delete_label(user_project)
end
desc 'Promote a label to a group label' do
detail 'This feature was added in GitLab 12.4.'
success Entities::GroupLabel
end
params do
requires :name, type: String, desc: 'The name or id of the label to be promoted'
end
put ':id/labels/:name/promote' do
promote_label(user_project)
end
2014-08-12 08:16:25 -04:00
end
end
end