summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMario de la Ossa <mariodelaossa@gmail.com>2018-06-15 16:05:24 -0600
committerAlexandru Croitor <acroitor@gitlab.com>2019-03-06 12:56:29 +0200
commitee8cb2d1b37c5c0d990a35af29be2877092eef29 (patch)
treed43ebcff7e8c24dd31ed3f437ca5c69c8553e51c
parentc19c5197e1307e12966da86f13744009b03fcea4 (diff)
downloadgitlab-ce-ee8cb2d1b37c5c0d990a35af29be2877092eef29.tar.gz
PUT MergeRequest API endpoint - accept labels as an array
-rw-r--r--lib/api/merge_requests.rb4
-rw-r--r--spec/requests/api/merge_requests_spec.rb13
2 files changed, 15 insertions, 2 deletions
diff --git a/lib/api/merge_requests.rb b/lib/api/merge_requests.rb
index 44f1e81caf2..2e794076a43 100644
--- a/lib/api/merge_requests.rb
+++ b/lib/api/merge_requests.rb
@@ -179,8 +179,8 @@ module API
optional :description, type: String, desc: 'The description of the merge request'
optional :assignee_id, type: Integer, desc: 'The ID of a user to assign the merge request'
optional :milestone_id, type: Integer, desc: 'The ID of a milestone to assign the merge request'
- optional :labels, type: String, desc: 'Comma-separated list of label names'
- optional :remove_source_branch, type: Boolean, desc: 'Delete source branch when merging'
+ optional :labels, type: String, coerce_with: ->(val) { val.is_a?(Array) ? val.join(', ') : val }, desc: 'Comma-separated list of label names'
+ optional :remove_source_branch, type: Boolean, desc: 'Remove source branch when merging'
optional :allow_collaboration, type: Boolean, desc: 'Allow commits from members who can merge to the target branch'
optional :allow_maintainer_to_push, type: Boolean, as: :allow_collaboration, desc: '[deprecated] See allow_collaboration'
optional :squash, type: Grape::API::Boolean, desc: 'When true, the commits will be squashed into a single commit on merge'
diff --git a/spec/requests/api/merge_requests_spec.rb b/spec/requests/api/merge_requests_spec.rb
index 6272bb38d59..79acb76a957 100644
--- a/spec/requests/api/merge_requests_spec.rb
+++ b/spec/requests/api/merge_requests_spec.rb
@@ -1137,6 +1137,19 @@ describe API::MergeRequests do
expect(json_response['labels']).to include '&'
end
+ it 'also accepts labels as an array' do
+ put api("/projects/#{project.id}/merge_requests/#{merge_request.iid}", user),
+ title: 'new issue',
+ labels: ['label', 'label?', 'label&foo', '?', '&']
+
+ expect(response.status).to eq(200)
+ expect(json_response['labels']).to include 'label'
+ expect(json_response['labels']).to include 'label?'
+ expect(json_response['labels']).to include 'label&foo'
+ expect(json_response['labels']).to include '?'
+ expect(json_response['labels']).to include '&'
+ end
+
it 'does not update state when title is empty' do
put api("/projects/#{project.id}/merge_requests/#{merge_request.iid}", user), params: { state_event: 'close', title: nil }