2020-05-29 05:08:06 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Mutations
|
|
|
|
module Commits
|
|
|
|
class Create < BaseMutation
|
2022-02-15 07:14:49 -05:00
|
|
|
graphql_name 'CommitCreate'
|
|
|
|
|
2021-01-26 13:09:30 -05:00
|
|
|
include FindsProject
|
2020-05-29 05:08:06 -04:00
|
|
|
|
2021-04-27 02:09:45 -04:00
|
|
|
class UrlHelpers
|
|
|
|
include GitlabRoutingHelper
|
|
|
|
include Gitlab::Routing
|
|
|
|
end
|
|
|
|
|
2021-07-23 11:09:21 -04:00
|
|
|
argument :project_path, GraphQL::Types::ID,
|
2020-05-29 05:08:06 -04:00
|
|
|
required: true,
|
2021-01-07 07:10:24 -05:00
|
|
|
description: 'Project full path the branch is associated with.'
|
2020-05-29 05:08:06 -04:00
|
|
|
|
2021-07-23 11:09:21 -04:00
|
|
|
argument :branch, GraphQL::Types::String,
|
2020-05-29 05:08:06 -04:00
|
|
|
required: true,
|
2021-01-07 07:10:24 -05:00
|
|
|
description: 'Name of the branch to commit into, it can be a new branch.'
|
2020-11-12 10:09:09 -05:00
|
|
|
|
2021-07-23 11:09:21 -04:00
|
|
|
argument :start_branch, GraphQL::Types::String,
|
2020-11-12 10:09:09 -05:00
|
|
|
required: false,
|
2021-01-07 07:10:24 -05:00
|
|
|
description: 'If on a new branch, name of the original branch.'
|
2020-05-29 05:08:06 -04:00
|
|
|
|
|
|
|
argument :message,
|
2021-07-23 11:09:21 -04:00
|
|
|
GraphQL::Types::String,
|
2020-05-29 05:08:06 -04:00
|
|
|
required: true,
|
|
|
|
description: copy_field_description(Types::CommitType, :message)
|
|
|
|
|
|
|
|
argument :actions,
|
|
|
|
[Types::CommitActionType],
|
|
|
|
required: true,
|
2021-01-07 07:10:24 -05:00
|
|
|
description: 'Array of action hashes to commit as a batch.'
|
2020-05-29 05:08:06 -04:00
|
|
|
|
2021-04-27 02:09:45 -04:00
|
|
|
field :commit_pipeline_path,
|
2021-07-23 11:09:21 -04:00
|
|
|
GraphQL::Types::String,
|
2021-04-27 02:09:45 -04:00
|
|
|
null: true,
|
|
|
|
description: "ETag path for the commit's pipeline."
|
|
|
|
|
2020-05-29 05:08:06 -04:00
|
|
|
field :commit,
|
|
|
|
Types::CommitType,
|
|
|
|
null: true,
|
2021-08-11 23:10:11 -04:00
|
|
|
description: 'Commit after mutation.'
|
2020-05-29 05:08:06 -04:00
|
|
|
|
2021-05-24 14:10:28 -04:00
|
|
|
field :content,
|
2021-07-23 11:09:21 -04:00
|
|
|
[GraphQL::Types::String],
|
2021-05-24 14:10:28 -04:00
|
|
|
null: true,
|
|
|
|
description: 'Contents of the commit.'
|
|
|
|
|
2020-05-29 05:08:06 -04:00
|
|
|
authorize :push_code
|
|
|
|
|
2020-11-12 10:09:09 -05:00
|
|
|
def resolve(project_path:, branch:, message:, actions:, **args)
|
2021-01-26 13:09:30 -05:00
|
|
|
project = authorized_find!(project_path)
|
2020-05-29 05:08:06 -04:00
|
|
|
|
|
|
|
attributes = {
|
|
|
|
commit_message: message,
|
|
|
|
branch_name: branch,
|
2020-11-12 10:09:09 -05:00
|
|
|
start_branch: args[:start_branch] || branch,
|
2020-05-29 05:08:06 -04:00
|
|
|
actions: actions.map { |action| action.to_h }
|
|
|
|
}
|
|
|
|
|
|
|
|
result = ::Files::MultiService.new(project, current_user, attributes).execute
|
|
|
|
|
|
|
|
{
|
2021-05-24 14:10:28 -04:00
|
|
|
content: actions.pluck(:content), # rubocop:disable CodeReuse/ActiveRecord because actions is an Array, not a Relation
|
2020-05-29 05:08:06 -04:00
|
|
|
commit: (project.repository.commit(result[:result]) if result[:status] == :success),
|
2021-04-27 02:09:45 -04:00
|
|
|
commit_pipeline_path: UrlHelpers.new.graphql_etag_pipeline_sha_path(result[:result]),
|
2020-05-29 05:08:06 -04:00
|
|
|
errors: Array.wrap(result[:message])
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|