Commit 4e041c9b authored by Stan Hu's avatar Stan Hu

Merge branch '354091-add-merge_request_diff_head_sha-to-createnote-input-parameters' into 'master'

Resolve "Add merge_request_diff_head_sha to CreateNote input parameters"

See merge request gitlab-org/gitlab!82248
parents b45205a0 a201e850
......@@ -3,6 +3,12 @@
module Mutations
module Notes
class Base < BaseMutation
QUICK_ACTION_ONLY_WARNING = <<~NB
If the body of the Note contains only quick actions,
the Note will be destroyed during an update, and no Note will be
returned.
NB
field :note,
Types::Notes::NoteType,
null: true,
......
......@@ -5,12 +5,18 @@ module Mutations
module Create
class Note < Base
graphql_name 'CreateNote'
description "Creates a Note.\n#{QUICK_ACTION_ONLY_WARNING}"
argument :discussion_id,
::Types::GlobalIDType[::Discussion],
required: false,
description: 'Global ID of the discussion this note is in reply to.'
argument :merge_request_diff_head_sha,
GraphQL::Types::String,
required: false,
description: 'SHA of the head commit which is used to ensure that the merge request has not been updated since the request was sent.'
private
def create_note_params(noteable, args)
......@@ -28,7 +34,8 @@ module Mutations
end
super(noteable, args).merge({
in_reply_to_discussion_id: discussion_id
in_reply_to_discussion_id: discussion_id,
merge_request_diff_head_sha: args[:merge_request_diff_head_sha]
})
end
......
......@@ -6,12 +6,6 @@ module Mutations
# This is a Base class for the Note update mutations and is not
# mounted as a GraphQL mutation itself.
class Base < Mutations::Notes::Base
QUICK_ACTION_ONLY_WARNING = <<~NB
If the body of the Note contains only quick actions,
the Note will be destroyed during the update, and no Note will be
returned.
NB
authorize :admin_note
argument :id,
......
......@@ -1485,6 +1485,11 @@ Input type: `CreateIterationInput`
### `Mutation.createNote`
Creates a Note.
If the body of the Note contains only quick actions,
the Note will be destroyed during an update, and no Note will be
returned.
Input type: `CreateNoteInput`
#### Arguments
......@@ -1495,6 +1500,7 @@ Input type: `CreateNoteInput`
| <a id="mutationcreatenoteclientmutationid"></a>`clientMutationId` | [`String`](#string) | A unique identifier for the client performing the mutation. |
| <a id="mutationcreatenoteconfidential"></a>`confidential` | [`Boolean`](#boolean) | Confidentiality flag of a note. Default is false. |
| <a id="mutationcreatenotediscussionid"></a>`discussionId` | [`DiscussionID`](#discussionid) | Global ID of the discussion this note is in reply to. |
| <a id="mutationcreatenotemergerequestdiffheadsha"></a>`mergeRequestDiffHeadSha` | [`String`](#string) | SHA of the head commit which is used to ensure that the merge request has not been updated since the request was sent. |
| <a id="mutationcreatenotenoteableid"></a>`noteableId` | [`NoteableID!`](#noteableid) | Global ID of the resource to add a note to. |
#### Fields
......@@ -4831,7 +4837,7 @@ Input type: `UpdateEpicBoardListInput`
Updates a DiffNote on an image (a `Note` where the `position.positionType` is `"image"`).
If the body of the Note contains only quick actions,
the Note will be destroyed during the update, and no Note will be
the Note will be destroyed during an update, and no Note will be
returned.
Input type: `UpdateImageDiffNoteInput`
......@@ -4938,7 +4944,7 @@ Input type: `UpdateNamespacePackageSettingsInput`
Updates a Note.
If the body of the Note contains only quick actions,
the Note will be destroyed during the update, and no Note will be
the Note will be destroyed during an update, and no Note will be
returned.
Input type: `UpdateNoteInput`
......@@ -8,13 +8,16 @@ RSpec.describe 'Adding a Note' do
let_it_be(:current_user) { create(:user) }
let(:noteable) { create(:merge_request, source_project: project, target_project: project) }
let(:project) { create(:project) }
let(:project) { create(:project, :repository) }
let(:discussion) { nil }
let(:head_sha) { nil }
let(:body) { 'Body text' }
let(:mutation) do
variables = {
noteable_id: GitlabSchema.id_from_object(noteable).to_s,
discussion_id: (GitlabSchema.id_from_object(discussion).to_s if discussion),
body: 'Body text',
merge_request_diff_head_sha: head_sha.presence,
body: body,
confidential: true
}
......@@ -54,7 +57,7 @@ RSpec.describe 'Adding a Note' do
let(:discussion) { create(:discussion_note).to_discussion }
it_behaves_like 'a mutation that returns top-level errors',
errors: ["The discussion does not exist or you don't have permission to perform this action"]
errors: ["The discussion does not exist or you don't have permission to perform this action"]
end
context 'when the user has permission to create notes on the discussion' do
......@@ -75,5 +78,29 @@ RSpec.describe 'Adding a Note' do
end
end
end
context 'when body only contains quick actions' do
let(:head_sha) { noteable.diff_head_sha }
let(:body) { '/merge' }
before do
project.add_developer(current_user)
end
# NOTE: Known issue https://gitlab.com/gitlab-org/gitlab/-/issues/346557
it 'returns a nil note and info about the command in errors' do
post_graphql_mutation(mutation, current_user: current_user)
expect(mutation_response).to include(
'errors' => [/Merged this merge request/],
'note' => nil
)
end
it 'starts the merge process' do
expect { post_graphql_mutation(mutation, current_user: current_user) }
.to change { noteable.reload.merge_jid.present? }.from(false).to(true)
end
end
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