diff options
author | Rémy Coutable <remy@rymai.me> | 2019-02-25 13:51:58 +0300 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2019-02-25 13:51:58 +0300 |
commit | 7981c0292b07a0138b096fa082341fcb13e9ce2b (patch) | |
tree | 6b2d16f4df9844f80eb76cdb8a7bf042215b526d /lib | |
parent | 9202bbd129537a698b986e6295d0c783b5a84815 (diff) | |
parent | 64ed7069c709949c0839aebe62d58191f75fa050 (diff) |
Merge branch '49449-add-an-api-endpoint-for-bulk-updating-issues-and-mrs' into 'master'
API endpoint for bulk updating issues and MRs
Closes #49449
See merge request gitlab-org/gitlab-ce!25201
Diffstat (limited to 'lib')
-rw-r--r-- | lib/api/api.rb | 1 | ||||
-rw-r--r-- | lib/api/issuable_bulk_update.rb | 51 |
2 files changed, 52 insertions, 0 deletions
diff --git a/lib/api/api.rb b/lib/api/api.rb index 4dd1b459554..3bcf5150b43 100644 --- a/lib/api/api.rb +++ b/lib/api/api.rb @@ -115,6 +115,7 @@ module API mount ::API::GroupVariables mount ::API::ImportGithub mount ::API::Internal + mount ::API::IssuableBulkUpdate mount ::API::Issues mount ::API::JobArtifacts mount ::API::Jobs diff --git a/lib/api/issuable_bulk_update.rb b/lib/api/issuable_bulk_update.rb new file mode 100644 index 00000000000..5ac6c252d96 --- /dev/null +++ b/lib/api/issuable_bulk_update.rb @@ -0,0 +1,51 @@ +# frozen_string_literal: true + +module API + class IssuableBulkUpdate < Grape::API + params do + requires :id, type: String, desc: 'The ID of a project' + end + resource :projects, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do + %w(issue merge_request).each do |issuable| + desc "Updates a list of #{issuable.pluralize}" do + detail 'This feature was introduced in 11.9' + end + params do + requires :issuable_ids, type: Array[Integer], desc: "Array of #{issuable.pluralize} IDs to be updated" + optional :state_event, type: String, values: %w(reopen close), desc: 'Reopens or closes a resource' + optional :milestone_id, type: Integer, desc: 'The milestone ID number' + optional :add_label_ids, type: Array[Integer], desc: 'IDs of labels to be added' + optional :remove_label_ids, type: Array[Integer], desc: 'IDs of labels to be removed' + optional :subscription_event, type: String, values: %w(subscribe unsubscribe), + desc: 'Subscribes or unsubscribes from a resource' + + if issuable == 'issue' + optional :assignee_ids, type: Array[Integer], desc: 'List of assignee IDs' + at_least_one_of :state_event, :milestone_id, :add_label_ids, :remove_label_ids, + :subscription_event, :assignee_ids + else + optional :assignee_id, type: Integer, desc: 'ID of the assignee' + at_least_one_of :state_event, :milestone_id, :add_label_ids, :remove_label_ids, + :subscription_event, :assignee_id + end + end + put ":id/#{issuable.pluralize}/bulk_update" do + authorize! :"admin_#{issuable}", user_project + + update_params = declared_params(include_missing: false) + + result = Issuable::BulkUpdateService.new(user_project, current_user, update_params) + .execute(issuable) + + if result[:success] + status 200 + quantity = result[:count] + { message: "#{quantity} #{issuable.pluralize(quantity)} updated" } + else + render_api_error!('Bulk update failed', 400) + end + end + end + end + end +end |