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
7fc870f8
Commit
7fc870f8
authored
Feb 13, 2021
by
Alex Kalderimis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add state events to merge request update mutation
This adds the ability to open and close MRs from GraphQL
parent
30741c7a
Changes
9
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
127 additions
and
4 deletions
+127
-4
app/graphql/mutations/merge_requests/update.rb
app/graphql/mutations/merge_requests/update.rb
+8
-3
app/graphql/types/merge_request_state_event_enum.rb
app/graphql/types/merge_request_state_event_enum.rb
+16
-0
app/models/merge_request.rb
app/models/merge_request.rb
+4
-0
changelogs/unreleased/ajk-add-state-events-to-mr-update-mutation.yml
...unreleased/ajk-add-state-events-to-mr-update-mutation.yml
+5
-0
doc/api/graphql/reference/gitlab_schema.graphql
doc/api/graphql/reference/gitlab_schema.graphql
+20
-0
doc/api/graphql/reference/gitlab_schema.json
doc/api/graphql/reference/gitlab_schema.json
+33
-0
doc/api/graphql/reference/index.md
doc/api/graphql/reference/index.md
+9
-0
spec/graphql/mutations/merge_requests/update_spec.rb
spec/graphql/mutations/merge_requests/update_spec.rb
+20
-1
spec/graphql/types/merge_request_state_event_enum_spec.rb
spec/graphql/types/merge_request_state_event_enum_spec.rb
+12
-0
No files found.
app/graphql/mutations/merge_requests/update.rb
View file @
7fc870f8
...
...
@@ -19,9 +19,14 @@ module Mutations
required:
false
,
description:
copy_field_description
(
Types
::
MergeRequestType
,
:description
)
def
resolve
(
args
)
merge_request
=
authorized_find!
(
**
args
.
slice
(
:project_path
,
:iid
))
attributes
=
args
.
slice
(
:title
,
:description
,
:target_branch
).
compact
argument
:state
,
::
Types
::
MergeRequestStateEventEnum
,
required:
false
,
as: :state_event
,
description:
'The action to perform to change the state.'
def
resolve
(
project_path
:,
iid
:,
**
args
)
merge_request
=
authorized_find!
(
project_path:
project_path
,
iid:
iid
)
attributes
=
args
.
compact
::
MergeRequests
::
UpdateService
.
new
(
merge_request
.
project
,
current_user
,
attributes
)
...
...
app/graphql/types/merge_request_state_event_enum.rb
0 → 100644
View file @
7fc870f8
# frozen_string_literal: true
module
Types
class
MergeRequestStateEventEnum
<
BaseEnum
graphql_name
'MergeRequestNewState'
description
'New state to apply to a merge request.'
value
'OPEN'
,
value:
'reopen'
,
description:
'Open the merge request if it is closed.'
value
'CLOSED'
,
value:
'close'
,
description:
'Close the merge request if it is open.'
end
end
app/models/merge_request.rb
View file @
7fc870f8
...
...
@@ -921,6 +921,10 @@ class MergeRequest < ApplicationRecord
closed?
&&
!
source_project_missing?
&&
source_branch_exists?
end
def
can_be_closed?
opened?
end
def
ensure_merge_request_diff
merge_request_diff
.
persisted?
||
create_merge_request_diff
end
...
...
changelogs/unreleased/ajk-add-state-events-to-mr-update-mutation.yml
0 → 100644
View file @
7fc870f8
---
title
:
Add state events to merge request update mutation
merge_request
:
54133
author
:
type
:
added
doc/api/graphql/reference/gitlab_schema.graphql
View file @
7fc870f8
...
...
@@ -15841,6 +15841,21 @@ Identifier of MergeRequest.
"""
scalar
MergeRequestID
"""
New state to apply to a merge request.
"""
enum
MergeRequestNewState
{
"""
Close
the
merge
request
if
it
is
open
.
"""
CLOSED
"""
Open
the
merge
request
if
it
is
closed
.
"""
OPEN
}
"""
Check permissions for the current user on a merge request
"""
...
...
@@ -16340,6 +16355,11 @@ input MergeRequestUpdateInput {
"""
projectPath
:
ID
!
"""
The
action
to
perform
to
change
the
state
.
"""
state
:
MergeRequestNewState
"""
Target
branch
of
the
merge
request
.
"""
...
...
doc/api/graphql/reference/gitlab_schema.json
View file @
7fc870f8
...
...
@@ -43339,6 +43339,29 @@
"enumValues": null,
"possibleTypes": null
},
{
"kind": "ENUM",
"name": "MergeRequestNewState",
"description": "New state to apply to a merge request.",
"fields": null,
"inputFields": null,
"interfaces": null,
"enumValues": [
{
"name": "OPEN",
"description": "Open the merge request if it is closed.",
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "CLOSED",
"description": "Close the merge request if it is open.",
"isDeprecated": false,
"deprecationReason": null
}
],
"possibleTypes": null
},
{
"kind": "OBJECT",
"name": "MergeRequestPermissions",
...
...
@@ -44668,6 +44691,16 @@
},
"defaultValue": null
},
{
"name": "state",
"description": "The action to perform to change the state.",
"type": {
"kind": "ENUM",
"name": "MergeRequestNewState",
"ofType": null
},
"defaultValue": null
},
{
"name": "clientMutationId",
"description": "A unique identifier for the client performing the mutation.",
doc/api/graphql/reference/index.md
View file @
7fc870f8
...
...
@@ -5111,6 +5111,15 @@ Possible identifier types for a measurement.
|
`PROJECTS`
| Project count |
|
`USERS`
| User count |
### MergeRequestNewState
New state to apply to a merge request..
| Value | Description |
| ----- | ----------- |
|
`CLOSED`
| Close the merge request if it is open. |
|
`OPEN`
| Open the merge request if it is closed. |
### MergeRequestSort
Values for sorting merge requests.
...
...
spec/graphql/mutations/merge_requests/update_spec.rb
View file @
7fc870f8
...
...
@@ -12,10 +12,11 @@ RSpec.describe Mutations::MergeRequests::Update do
describe
'#resolve'
do
let
(
:attributes
)
{
{
title:
'new title'
,
description:
'new description'
,
target_branch:
'new-branch'
}
}
let
(
:arguments
)
{
attributes
}
let
(
:mutated_merge_request
)
{
subject
[
:merge_request
]
}
subject
do
mutation
.
resolve
(
project_path:
merge_request
.
project
.
full_path
,
iid:
merge_request
.
iid
,
**
a
ttribute
s
)
mutation
.
resolve
(
project_path:
merge_request
.
project
.
full_path
,
iid:
merge_request
.
iid
,
**
a
rgument
s
)
end
it_behaves_like
'permission level for merge request mutation is correctly verified'
...
...
@@ -61,6 +62,24 @@ RSpec.describe Mutations::MergeRequests::Update do
expect
(
mutated_merge_request
).
to
have_attributes
(
attributes
)
end
end
context
'when closing the MR'
do
let
(
:arguments
)
{
{
state_event:
::
Types
::
MergeRequestStateEventEnum
.
values
[
'CLOSED'
].
value
}
}
it
'closes the MR'
do
expect
(
mutated_merge_request
).
to
be_closed
end
end
context
'when re-opening the MR'
do
let
(
:arguments
)
{
{
state_event:
::
Types
::
MergeRequestStateEventEnum
.
values
[
'OPEN'
].
value
}
}
it
'closes the MR'
do
merge_request
.
close!
expect
(
mutated_merge_request
).
to
be_open
end
end
end
end
end
spec/graphql/types/merge_request_state_event_enum_spec.rb
0 → 100644
View file @
7fc870f8
# frozen_string_literal: true
require
'spec_helper'
RSpec
.
describe
GitlabSchema
.
types
[
'MergeRequestNewState'
]
do
it
'has the appropriate values'
do
expect
(
described_class
.
values
).
to
contain_exactly
(
[
'OPEN'
,
have_attributes
(
value:
'reopen'
)],
[
'CLOSED'
,
have_attributes
(
value:
'close'
)]
)
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