Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
68170bc4
Commit
68170bc4
authored
Jul 23, 2020
by
Eugenia Grieff
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add labels to issues update mutation
- Ability to add and remove labels from an issue using GraphQL
parent
bff83d42
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
113 additions
and
3 deletions
+113
-3
app/graphql/mutations/issues/update.rb
app/graphql/mutations/issues/update.rb
+10
-0
changelogs/unreleased/208782-graphql-api-mutation-for-changing-labels-of-an-issue.yml
...-graphql-api-mutation-for-changing-labels-of-an-issue.yml
+5
-0
doc/api/graphql/reference/gitlab_schema.graphql
doc/api/graphql/reference/gitlab_schema.graphql
+10
-0
doc/api/graphql/reference/gitlab_schema.json
doc/api/graphql/reference/gitlab_schema.json
+36
-0
spec/graphql/mutations/issues/update_spec.rb
spec/graphql/mutations/issues/update_spec.rb
+52
-3
No files found.
app/graphql/mutations/issues/update.rb
View file @
68170bc4
...
...
@@ -31,6 +31,16 @@ module Mutations
required:
false
,
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
)
issue
=
authorized_find!
(
project_path:
project_path
,
iid:
iid
)
project
=
issue
.
project
...
...
changelogs/unreleased/208782-graphql-api-mutation-for-changing-labels-of-an-issue.yml
0 → 100644
View file @
68170bc4
---
title
:
Allow user to update issue labels via GraphQL
merge_request
:
37728
author
:
type
:
added
doc/api/graphql/reference/gitlab_schema.graphql
View file @
68170bc4
...
...
@@ -14128,6 +14128,11 @@ type UpdateImageDiffNotePayload {
Autogenerated input type of UpdateIssue
"""
input
UpdateIssueInput
{
"""
The
IDs
of
labels
to
be
added
to
the
issue
.
"""
addLabelIds
:
[
ID
!]
"""
A
unique
identifier
for
the
client
performing
the
mutation
.
"""
...
...
@@ -14168,6 +14173,11 @@ input UpdateIssueInput {
"""
projectPath
:
ID
!
"""
The
IDs
of
labels
to
be
removed
from
the
issue
.
"""
removeLabelIds
:
[
ID
!]
"""
Title
of
the
issue
"""
...
...
doc/api/graphql/reference/gitlab_schema.json
View file @
68170bc4
...
...
@@ -41855,6 +41855,42 @@
},
"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",
"description": "The desired health status",
spec/graphql/mutations/issues/update_spec.rb
View file @
68170bc4
...
...
@@ -3,8 +3,11 @@
require
'spec_helper'
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
(
:project_label
)
{
create
(
:label
,
project:
project
)
}
let_it_be
(
:issue
)
{
create
(
:issue
,
project:
project
,
labels:
[
project_label
])
}
let
(
:expected_attributes
)
do
{
title:
'new title'
,
...
...
@@ -22,7 +25,7 @@ RSpec.describe Mutations::Issues::Update do
describe
'#resolve'
do
let
(
:mutation_params
)
do
{
project_path:
issue
.
project
.
full_path
,
project_path:
project
.
full_path
,
iid:
issue
.
iid
}.
merge
(
expected_attributes
)
end
...
...
@@ -37,7 +40,7 @@ RSpec.describe Mutations::Issues::Update do
context
'when the user can update the issue'
do
before
do
issue
.
project
.
add_developer
(
user
)
project
.
add_developer
(
user
)
end
it
'updates issue with correct values'
do
...
...
@@ -53,6 +56,52 @@ RSpec.describe Mutations::Issues::Update do
expect
{
subject
}.
to
raise_error
(
Gitlab
::
Graphql
::
Errors
::
ResourceNotAvailable
)
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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment