Commit 44deddc2 authored by Robert Speicher's avatar Robert Speicher

Merge branch '215619-add-new-arguments-to-merge-request-mutation' into 'master'

Add `labels` argument to merge request mutation

Closes #215619

See merge request gitlab-org/gitlab!32637
parents 58e7075d aba7727a
...@@ -27,6 +27,10 @@ module Mutations ...@@ -27,6 +27,10 @@ module Mutations
required: false, required: false,
description: copy_field_description(Types::MergeRequestType, :description) description: copy_field_description(Types::MergeRequestType, :description)
argument :labels, [GraphQL::STRING_TYPE],
required: false,
description: copy_field_description(Types::MergeRequestType, :labels)
field :merge_request, field :merge_request,
Types::MergeRequestType, Types::MergeRequestType,
null: true, null: true,
...@@ -34,18 +38,11 @@ module Mutations ...@@ -34,18 +38,11 @@ module Mutations
authorize :create_merge_request_from authorize :create_merge_request_from
def resolve(project_path:, title:, source_branch:, target_branch:, description: nil) def resolve(project_path:, **attributes)
project = authorized_find!(full_path: project_path) project = authorized_find!(full_path: project_path)
params = attributes.merge(author_id: current_user.id)
attributes = { merge_request = ::MergeRequests::CreateService.new(project, current_user, params).execute
title: title,
source_branch: source_branch,
target_branch: target_branch,
author_id: current_user.id,
description: description
}
merge_request = ::MergeRequests::CreateService.new(project, current_user, attributes).execute
{ {
merge_request: merge_request.valid? ? merge_request : nil, merge_request: merge_request.valid? ? merge_request : nil,
......
---
title: Allow labels argument for merge request create mutation
merge_request: 32637
author:
type: added
...@@ -7462,6 +7462,11 @@ input MergeRequestCreateInput { ...@@ -7462,6 +7462,11 @@ input MergeRequestCreateInput {
""" """
description: String description: String
"""
Labels of the merge request
"""
labels: [String!]
""" """
Project full path the merge request is associated with Project full path the merge request is associated with
""" """
......
...@@ -20832,6 +20832,24 @@ ...@@ -20832,6 +20832,24 @@
}, },
"defaultValue": null "defaultValue": null
}, },
{
"name": "labels",
"description": "Labels of the merge request",
"type": {
"kind": "LIST",
"name": null,
"ofType": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "String",
"ofType": null
}
}
},
"defaultValue": null
},
{ {
"name": "clientMutationId", "name": "clientMutationId",
"description": "A unique identifier for the client performing the mutation.", "description": "A unique identifier for the client performing the mutation.",
...@@ -22,7 +22,8 @@ RSpec.describe Mutations::MergeRequests::Create do ...@@ -22,7 +22,8 @@ RSpec.describe Mutations::MergeRequests::Create do
title: title, title: title,
source_branch: source_branch, source_branch: source_branch,
target_branch: target_branch, target_branch: target_branch,
description: description description: description,
labels: labels
) )
end end
...@@ -30,6 +31,7 @@ RSpec.describe Mutations::MergeRequests::Create do ...@@ -30,6 +31,7 @@ RSpec.describe Mutations::MergeRequests::Create do
let(:source_branch) { 'feature' } let(:source_branch) { 'feature' }
let(:target_branch) { 'master' } let(:target_branch) { 'master' }
let(:description) { nil } let(:description) { nil }
let(:labels) { nil }
let(:mutated_merge_request) { subject[:merge_request] } let(:mutated_merge_request) { subject[:merge_request] }
...@@ -70,6 +72,15 @@ RSpec.describe Mutations::MergeRequests::Create do ...@@ -70,6 +72,15 @@ RSpec.describe Mutations::MergeRequests::Create do
end end
end end
context 'when optional labels field is set' do
let(:labels) { %w[label-1 label-2] }
it 'returns a new merge request with labels' do
expect(mutated_merge_request.labels.map(&:title)).to eq(labels)
expect(subject[:errors]).to be_empty
end
end
context 'when service cannot create a merge request' do context 'when service cannot create a merge request' do
let(:title) { nil } let(:title) { nil }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment