Skip to content
Snippets Groups Projects
Commit 7fc870f8 authored by Alexis Kalderimis's avatar Alexis Kalderimis :speech_balloon:
Browse files

Add state events to merge request update mutation

This adds the ability to open and close MRs from GraphQL
parent 30741c7a
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -19,9 +19,14 @@ class Update < Base
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)
Loading
Loading
# 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
Loading
Loading
@@ -921,6 +921,10 @@ def reopenable?
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
Loading
Loading
---
title: Add state events to merge request update mutation
merge_request: 54133
author:
type: added
Loading
Loading
@@ -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
"""
Loading
Loading
@@ -16340,6 +16355,11 @@ input MergeRequestUpdateInput {
"""
projectPath: ID!
 
"""
The action to perform to change the state.
"""
state: MergeRequestNewState
"""
Target branch of the merge request.
"""
Loading
Loading
Loading
Loading
@@ -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",
Loading
Loading
@@ -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.",
Loading
Loading
@@ -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.
Loading
Loading
Loading
Loading
@@ -12,10 +12,11 @@
 
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, **attributes)
mutation.resolve(project_path: merge_request.project.full_path, iid: merge_request.iid, **arguments)
end
 
it_behaves_like 'permission level for merge request mutation is correctly verified'
Loading
Loading
@@ -61,6 +62,24 @@
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
# 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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment