Commit 11b656cf authored by Michael Kozono's avatar Michael Kozono

Merge branch 'lm-add-content-to-commit-create-mutation' into 'master'

Adds content to createCommit mutation

See merge request gitlab-org/gitlab!60938
parents d51370d4 bd5eaf0b
...@@ -44,6 +44,11 @@ module Mutations ...@@ -44,6 +44,11 @@ module Mutations
null: true, null: true,
description: 'The commit after mutation.' description: 'The commit after mutation.'
field :content,
[GraphQL::STRING_TYPE],
null: true,
description: 'Contents of the commit.'
authorize :push_code authorize :push_code
def resolve(project_path:, branch:, message:, actions:, **args) def resolve(project_path:, branch:, message:, actions:, **args)
...@@ -59,6 +64,7 @@ module Mutations ...@@ -59,6 +64,7 @@ module Mutations
result = ::Files::MultiService.new(project, current_user, attributes).execute result = ::Files::MultiService.new(project, current_user, attributes).execute
{ {
content: actions.pluck(:content), # rubocop:disable CodeReuse/ActiveRecord because actions is an Array, not a Relation
commit: (project.repository.commit(result[:result]) if result[:status] == :success), commit: (project.repository.commit(result[:result]) if result[:status] == :success),
commit_pipeline_path: UrlHelpers.new.graphql_etag_pipeline_sha_path(result[:result]), commit_pipeline_path: UrlHelpers.new.graphql_etag_pipeline_sha_path(result[:result]),
errors: Array.wrap(result[:message]) errors: Array.wrap(result[:message])
......
...@@ -882,6 +882,7 @@ Input type: `CommitCreateInput` ...@@ -882,6 +882,7 @@ Input type: `CommitCreateInput`
| <a id="mutationcommitcreateclientmutationid"></a>`clientMutationId` | [`String`](#string) | A unique identifier for the client performing the mutation. | | <a id="mutationcommitcreateclientmutationid"></a>`clientMutationId` | [`String`](#string) | A unique identifier for the client performing the mutation. |
| <a id="mutationcommitcreatecommit"></a>`commit` | [`Commit`](#commit) | The commit after mutation. | | <a id="mutationcommitcreatecommit"></a>`commit` | [`Commit`](#commit) | The commit after mutation. |
| <a id="mutationcommitcreatecommitpipelinepath"></a>`commitPipelinePath` | [`String`](#string) | ETag path for the commit's pipeline. | | <a id="mutationcommitcreatecommitpipelinepath"></a>`commitPipelinePath` | [`String`](#string) | ETag path for the commit's pipeline. |
| <a id="mutationcommitcreatecontent"></a>`content` | [`[String!]`](#string) | Contents of the commit. |
| <a id="mutationcommitcreateerrors"></a>`errors` | [`[String!]!`](#string) | Errors encountered during execution of the mutation. | | <a id="mutationcommitcreateerrors"></a>`errors` | [`[String!]!`](#string) | Errors encountered during execution of the mutation. |
### `Mutation.configureSast` ### `Mutation.configureSast`
......
...@@ -74,6 +74,10 @@ RSpec.describe Mutations::Commits::Create do ...@@ -74,6 +74,10 @@ RSpec.describe Mutations::Commits::Create do
expect(commit_pipeline_path).to match(%r(pipelines/sha/\w+)) expect(commit_pipeline_path).to match(%r(pipelines/sha/\w+))
end end
it 'returns the content of the commit' do
expect(subject[:content]).to eq(actions.pluck(:content))
end
it 'returns a new commit' do it 'returns a new commit' do
expect(mutated_commit).to have_attributes(message: message, project: project) expect(mutated_commit).to have_attributes(message: message, project: project)
expect(subject[:errors]).to be_empty expect(subject[:errors]).to be_empty
...@@ -166,6 +170,7 @@ RSpec.describe Mutations::Commits::Create do ...@@ -166,6 +170,7 @@ RSpec.describe Mutations::Commits::Create do
it 'returns a new commit' do it 'returns a new commit' do
expect(mutated_commit).to have_attributes(message: message, project: project) expect(mutated_commit).to have_attributes(message: message, project: project)
expect(subject[:errors]).to be_empty expect(subject[:errors]).to be_empty
expect(subject[:content]).to eq(actions.pluck(:content))
expect_to_contain_deltas([ expect_to_contain_deltas([
a_hash_including(a_mode: '0', b_mode: '100644', new_file: true, new_path: 'ANOTHER_FILE.md') a_hash_including(a_mode: '0', b_mode: '100644', new_file: true, new_path: 'ANOTHER_FILE.md')
......
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