debian-mirror-gitlab/app/graphql/mutations/commits/create.rb

76 lines
2.3 KiB
Ruby
Raw Normal View History

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