summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Schilling <rschilling@student.tugraz.at>2019-02-13 15:40:35 +0100
committerRobert Schilling <rschilling@student.tugraz.at>2019-02-14 11:45:28 +0100
commit9e521ca7007d32bd4e6491b3507de7d9ff8e4cef (patch)
treec6ad47c4f53c6cfc78b6c765db0feb17b1278a73
parent7a8f8714cc65b36b8dbc4fe180eeb73aa2eeba0f (diff)
downloadgitlab-ce-9e521ca7007d32bd4e6491b3507de7d9ff8e4cef.tar.gz
API: Bulk update for issues and merge requests
This MR adds support for bulk update actions for issues and merge requests. A single API call can be used to update a list of issues or merge requests
-rw-r--r--changelogs/unreleased/api-issuable-bulk-update.yml5
-rw-r--r--lib/api/api.rb1
-rw-r--r--lib/api/issuable_bulk_update.rb48
3 files changed, 54 insertions, 0 deletions
diff --git a/changelogs/unreleased/api-issuable-bulk-update.yml b/changelogs/unreleased/api-issuable-bulk-update.yml
new file mode 100644
index 00000000000..302484f5569
--- /dev/null
+++ b/changelogs/unreleased/api-issuable-bulk-update.yml
@@ -0,0 +1,5 @@
+---
+title: 'API: Bulk update for issues and MRs'
+merge_request:
+author:
+type: added
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..fe12242a676
--- /dev/null
+++ b/lib/api/issuable_bulk_update.rb
@@ -0,0 +1,48 @@
+# 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
+ 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 assignees 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}/bulk_update" do
+ update_params = declared_params(include_missing: false)
+
+ result = Issuable::BulkUpdateService.new(user_project, current_user, update_params)
+ .execute(issuable)
+ quantity = result[:count]
+
+ if result[:success]
+ status 200
+ { notice: "#{quantity} #{issuable.pluralize(quantity)} updated" }
+ else
+ render_api_error!('Bulk update failed', 400)
+ end
+ end
+ end
+ end
+ end
+end