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
required: false,
description: copy_field_description(Types::MergeRequestType, :description)
argument :labels, [GraphQL::STRING_TYPE],
required: false,
description: copy_field_description(Types::MergeRequestType, :labels)
field :merge_request,
Types::MergeRequestType,
null: true,
......@@ -34,18 +38,11 @@ module Mutations
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)
params = attributes.merge(author_id: current_user.id)
attributes = {
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 = ::MergeRequests::CreateService.new(project, current_user, params).execute
{
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 {
"""
description: String
"""
Labels of the merge request
"""
labels: [String!]
"""
Project full path the merge request is associated with
"""
......
......@@ -20832,6 +20832,24 @@
},
"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",
"description": "A unique identifier for the client performing the mutation.",
......@@ -22,7 +22,8 @@ RSpec.describe Mutations::MergeRequests::Create do
title: title,
source_branch: source_branch,
target_branch: target_branch,
description: description
description: description,
labels: labels
)
end
......@@ -30,6 +31,7 @@ RSpec.describe Mutations::MergeRequests::Create do
let(:source_branch) { 'feature' }
let(:target_branch) { 'master' }
let(:description) { nil }
let(:labels) { nil }
let(:mutated_merge_request) { subject[:merge_request] }
......@@ -70,6 +72,15 @@ RSpec.describe Mutations::MergeRequests::Create do
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
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