Commit b01cc485 authored by charlie ablett's avatar charlie ablett

Merge branch '208782-graphql-api-mutation-for-changing-labels-of-an-issue' into 'master'

Add labels to issues update mutation

See merge request gitlab-org/gitlab!37728
parents cc07a5da 68170bc4
...@@ -31,6 +31,16 @@ module Mutations ...@@ -31,6 +31,16 @@ module Mutations
required: false, required: false,
description: copy_field_description(Types::IssueType, :discussion_locked) description: copy_field_description(Types::IssueType, :discussion_locked)
argument :add_label_ids,
[GraphQL::ID_TYPE],
required: false,
description: 'The IDs of labels to be added to the issue.'
argument :remove_label_ids,
[GraphQL::ID_TYPE],
required: false,
description: 'The IDs of labels to be removed from the issue.'
def resolve(project_path:, iid:, **args) def resolve(project_path:, iid:, **args)
issue = authorized_find!(project_path: project_path, iid: iid) issue = authorized_find!(project_path: project_path, iid: iid)
project = issue.project project = issue.project
......
---
title: Allow user to update issue labels via GraphQL
merge_request: 37728
author:
type: added
...@@ -14169,6 +14169,11 @@ type UpdateImageDiffNotePayload { ...@@ -14169,6 +14169,11 @@ type UpdateImageDiffNotePayload {
Autogenerated input type of UpdateIssue Autogenerated input type of UpdateIssue
""" """
input UpdateIssueInput { input UpdateIssueInput {
"""
The IDs of labels to be added to the issue.
"""
addLabelIds: [ID!]
""" """
A unique identifier for the client performing the mutation. A unique identifier for the client performing the mutation.
""" """
...@@ -14209,6 +14214,11 @@ input UpdateIssueInput { ...@@ -14209,6 +14214,11 @@ input UpdateIssueInput {
""" """
projectPath: ID! projectPath: ID!
"""
The IDs of labels to be removed from the issue.
"""
removeLabelIds: [ID!]
""" """
Title of the issue Title of the issue
""" """
......
...@@ -41998,6 +41998,42 @@ ...@@ -41998,6 +41998,42 @@
}, },
"defaultValue": null "defaultValue": null
}, },
{
"name": "addLabelIds",
"description": "The IDs of labels to be added to the issue.",
"type": {
"kind": "LIST",
"name": null,
"ofType": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "ID",
"ofType": null
}
}
},
"defaultValue": null
},
{
"name": "removeLabelIds",
"description": "The IDs of labels to be removed from the issue.",
"type": {
"kind": "LIST",
"name": null,
"ofType": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "ID",
"ofType": null
}
}
},
"defaultValue": null
},
{ {
"name": "healthStatus", "name": "healthStatus",
"description": "The desired health status", "description": "The desired health status",
...@@ -3,8 +3,11 @@ ...@@ -3,8 +3,11 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe Mutations::Issues::Update do RSpec.describe Mutations::Issues::Update do
let_it_be(:issue) { create(:issue) } let_it_be(:project) { create(:project) }
let_it_be(:user) { create(:user) } let_it_be(:user) { create(:user) }
let_it_be(:project_label) { create(:label, project: project) }
let_it_be(:issue) { create(:issue, project: project, labels: [project_label]) }
let(:expected_attributes) do let(:expected_attributes) do
{ {
title: 'new title', title: 'new title',
...@@ -22,7 +25,7 @@ RSpec.describe Mutations::Issues::Update do ...@@ -22,7 +25,7 @@ RSpec.describe Mutations::Issues::Update do
describe '#resolve' do describe '#resolve' do
let(:mutation_params) do let(:mutation_params) do
{ {
project_path: issue.project.full_path, project_path: project.full_path,
iid: issue.iid iid: issue.iid
}.merge(expected_attributes) }.merge(expected_attributes)
end end
...@@ -37,7 +40,7 @@ RSpec.describe Mutations::Issues::Update do ...@@ -37,7 +40,7 @@ RSpec.describe Mutations::Issues::Update do
context 'when the user can update the issue' do context 'when the user can update the issue' do
before do before do
issue.project.add_developer(user) project.add_developer(user)
end end
it 'updates issue with correct values' do it 'updates issue with correct values' do
...@@ -53,6 +56,52 @@ RSpec.describe Mutations::Issues::Update do ...@@ -53,6 +56,52 @@ RSpec.describe Mutations::Issues::Update do
expect { subject }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable) expect { subject }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable)
end end
end end
context 'when changing labels' do
let_it_be(:label_1) { create(:label, project: project) }
let_it_be(:label_2) { create(:label, project: project) }
let_it_be(:external_label) { create(:label, project: create(:project)) }
it 'adds and removes labels correctly' do
mutation_params[:add_label_ids] = [label_1.id, label_2.id]
mutation_params[:remove_label_ids] = [project_label.id]
subject
expect(issue.reload.labels).to match_array([label_1, label_2])
end
it 'does not add label if label id is nil' do
mutation_params[:add_label_ids] = [nil, label_2.id]
subject
expect(issue.reload.labels).to match_array([project_label, label_2])
end
it 'does not add label if label is not found' do
mutation_params[:add_label_ids] = [external_label.id, label_2.id]
subject
expect(issue.reload.labels).to match_array([project_label, label_2])
end
it 'does not modify labels if label is already present' do
mutation_params[:add_label_ids] = [project_label.id]
expect(issue.reload.labels).to match_array([project_label])
end
it 'does not modify labels if label is addded and removed in the same request' do
mutation_params[:add_label_ids] = [label_1.id, label_2.id]
mutation_params[:remove_label_ids] = [label_1.id]
subject
expect(issue.reload.labels).to match_array([project_label, label_2])
end
end
end end
end end
end end
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