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

59 lines
1.7 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
graphql_name 'CommitCreate'
argument :project_path, GraphQL::ID_TYPE,
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
argument :branch, GraphQL::STRING_TYPE,
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
argument :start_branch, GraphQL::STRING_TYPE,
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,
GraphQL::STRING_TYPE,
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
field :commit,
Types::CommitType,
null: true,
2021-03-08 18:12:59 +05:30
description: 'The commit after mutation.'
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
{
commit: (project.repository.commit(result[:result]) if result[:status] == :success),
errors: Array.wrap(result[:message])
}
end
end
end
end