Commit 3e3c1c03 authored by Dmytro Zaporozhets (DZ)'s avatar Dmytro Zaporozhets (DZ)

Merge branch 'ajk-add-state-events-to-mr-update-mutation' into 'master'

Add state events to merge request update mutation

See merge request gitlab-org/gitlab!54133
parents 0b049a7b 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)
......
# 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
......@@ -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
......
---
title: Add state events to merge request update mutation
merge_request: 54133
author:
type: added
......@@ -15922,6 +15922,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
"""
......@@ -16421,6 +16436,11 @@ input MergeRequestUpdateInput {
"""
projectPath: ID!
"""
The action to perform to change the state.
"""
state: MergeRequestNewState
"""
Target branch of the merge request.
"""
......
......@@ -43527,6 +43527,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",
......@@ -44856,6 +44879,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.",
......@@ -5112,6 +5112,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.
......
......@@ -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, **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'
......@@ -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
# 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
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