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
7ce6726c
Commit
7ce6726c
authored
Nov 11, 2019
by
Mario de la Ossa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
GraphQL: Add MRSetLocked mutation
Adds a mutation to set a MergeRequest's `discussion_locked` attribute
parent
ce30cfef
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
158 additions
and
0 deletions
+158
-0
app/graphql/mutations/merge_requests/set_locked.rb
app/graphql/mutations/merge_requests/set_locked.rb
+29
-0
app/graphql/types/mutation_type.rb
app/graphql/types/mutation_type.rb
+1
-0
spec/graphql/mutations/merge_requests/set_locked_spec.rb
spec/graphql/mutations/merge_requests/set_locked_spec.rb
+49
-0
spec/requests/api/graphql/mutations/merge_requests/set_locked_spec.rb
...s/api/graphql/mutations/merge_requests/set_locked_spec.rb
+79
-0
No files found.
app/graphql/mutations/merge_requests/set_locked.rb
0 → 100644
View file @
7ce6726c
# frozen_string_literal: true
module
Mutations
module
MergeRequests
class
SetLocked
<
Base
graphql_name
'MergeRequestSetLocked'
argument
:locked
,
GraphQL
::
BOOLEAN_TYPE
,
required:
true
,
description:
<<~
DESC
Whether or not to lock the merge request.
DESC
def
resolve
(
project_path
:,
iid
:,
locked
:)
merge_request
=
authorized_find!
(
project_path:
project_path
,
iid:
iid
)
project
=
merge_request
.
project
::
MergeRequests
::
UpdateService
.
new
(
project
,
current_user
,
discussion_locked:
locked
)
.
execute
(
merge_request
)
{
merge_request:
merge_request
,
errors:
merge_request
.
errors
.
full_messages
}
end
end
end
end
app/graphql/types/mutation_type.rb
View file @
7ce6726c
...
@@ -10,6 +10,7 @@ module Types
...
@@ -10,6 +10,7 @@ module Types
mount_mutation
Mutations
::
AwardEmojis
::
Remove
mount_mutation
Mutations
::
AwardEmojis
::
Remove
mount_mutation
Mutations
::
AwardEmojis
::
Toggle
mount_mutation
Mutations
::
AwardEmojis
::
Toggle
mount_mutation
Mutations
::
MergeRequests
::
SetLabels
mount_mutation
Mutations
::
MergeRequests
::
SetLabels
mount_mutation
Mutations
::
MergeRequests
::
SetLocked
mount_mutation
Mutations
::
MergeRequests
::
SetMilestone
mount_mutation
Mutations
::
MergeRequests
::
SetMilestone
mount_mutation
Mutations
::
MergeRequests
::
SetWip
,
calls_gitaly:
true
mount_mutation
Mutations
::
MergeRequests
::
SetWip
,
calls_gitaly:
true
mount_mutation
Mutations
::
MergeRequests
::
SetAssignees
mount_mutation
Mutations
::
MergeRequests
::
SetAssignees
...
...
spec/graphql/mutations/merge_requests/set_locked_spec.rb
0 → 100644
View file @
7ce6726c
# frozen_string_literal: true
require
'spec_helper'
describe
Mutations
::
MergeRequests
::
SetLocked
do
let
(
:merge_request
)
{
create
(
:merge_request
)
}
let
(
:user
)
{
create
(
:user
)
}
subject
(
:mutation
)
{
described_class
.
new
(
object:
nil
,
context:
{
current_user:
user
})
}
describe
'#resolve'
do
let
(
:locked
)
{
true
}
let
(
:mutated_merge_request
)
{
subject
[
:merge_request
]
}
subject
{
mutation
.
resolve
(
project_path:
merge_request
.
project
.
full_path
,
iid:
merge_request
.
iid
,
locked:
locked
)
}
it
'raises an error if the resource is not accessible to the user'
do
expect
{
subject
}.
to
raise_error
(
Gitlab
::
Graphql
::
Errors
::
ResourceNotAvailable
)
end
context
'when the user can update the merge request'
do
before
do
merge_request
.
project
.
add_developer
(
user
)
end
it
'returns the merge request as discussion locked'
do
expect
(
mutated_merge_request
).
to
eq
(
merge_request
)
expect
(
mutated_merge_request
).
to
be_discussion_locked
expect
(
subject
[
:errors
]).
to
be_empty
end
it
'returns errors merge request could not be updated'
do
# Make the merge request invalid
merge_request
.
allow_broken
=
true
merge_request
.
update!
(
source_project:
nil
)
expect
(
subject
[
:errors
]).
not_to
be_empty
end
context
'when passing locked as false'
do
let
(
:locked
)
{
false
}
it
'unlocks the discussion'
do
merge_request
.
update
(
discussion_locked:
true
)
expect
(
mutated_merge_request
).
not_to
be_discussion_locked
end
end
end
end
end
spec/requests/api/graphql/mutations/merge_requests/set_locked_spec.rb
0 → 100644
View file @
7ce6726c
# frozen_string_literal: true
require
'spec_helper'
describe
'Setting locked status of a merge request'
do
include
GraphqlHelpers
let
(
:current_user
)
{
create
(
:user
)
}
let
(
:merge_request
)
{
create
(
:merge_request
)
}
let
(
:project
)
{
merge_request
.
project
}
let
(
:input
)
{
{
locked:
true
}
}
let
(
:mutation
)
do
variables
=
{
project_path:
project
.
full_path
,
iid:
merge_request
.
iid
.
to_s
}
graphql_mutation
(
:merge_request_set_locked
,
variables
.
merge
(
input
),
<<-
QL
.
strip_heredoc
clientMutationId
errors
mergeRequest {
id
discussionLocked
}
QL
)
end
def
mutation_response
graphql_mutation_response
(
:merge_request_set_locked
)[
'mergeRequest'
][
'discussionLocked'
]
end
before
do
project
.
add_developer
(
current_user
)
end
it
'returns an error if the user is not allowed to update the merge request'
do
post_graphql_mutation
(
mutation
,
current_user:
create
(
:user
))
expect
(
graphql_errors
).
not_to
be_empty
end
it
'marks the merge request as WIP'
do
post_graphql_mutation
(
mutation
,
current_user:
current_user
)
expect
(
response
).
to
have_gitlab_http_status
(
:success
)
expect
(
mutation_response
).
to
eq
(
true
)
end
it
'does not do anything if the merge request was already locked'
do
merge_request
.
update!
(
discussion_locked:
true
)
post_graphql_mutation
(
mutation
,
current_user:
current_user
)
expect
(
response
).
to
have_gitlab_http_status
(
:success
)
expect
(
mutation_response
).
to
eq
(
true
)
end
context
'when passing locked false as input'
do
let
(
:input
)
{
{
locked:
false
}
}
it
'does not do anything if the merge request was not marked locked'
do
post_graphql_mutation
(
mutation
,
current_user:
current_user
)
expect
(
response
).
to
have_gitlab_http_status
(
:success
)
expect
(
mutation_response
).
to
eq
(
false
)
end
it
'unmarks the merge request as locked'
do
merge_request
.
update!
(
discussion_locked:
true
)
post_graphql_mutation
(
mutation
,
current_user:
current_user
)
expect
(
response
).
to
have_gitlab_http_status
(
:success
)
expect
(
mutation_response
).
to
eq
(
false
)
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