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

55 lines
1.8 KiB
Ruby
Raw Normal View History

2020-06-23 00:09:42 +05:30
# frozen_string_literal: true
module Mutations
module MergeRequests
class Create < BaseMutation
2021-03-11 19:13:27 +05:30
include FindsProject
2020-06-23 00:09:42 +05:30
graphql_name 'MergeRequestCreate'
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 merge request is associated with.'
2020-06-23 00:09:42 +05:30
2021-10-27 15:23:28 +05:30
argument :title, GraphQL::Types::String,
2020-06-23 00:09:42 +05:30
required: true,
description: copy_field_description(Types::MergeRequestType, :title)
2021-10-27 15:23:28 +05:30
argument :source_branch, GraphQL::Types::String,
2020-06-23 00:09:42 +05:30
required: true,
description: copy_field_description(Types::MergeRequestType, :source_branch)
2021-10-27 15:23:28 +05:30
argument :target_branch, GraphQL::Types::String,
2020-06-23 00:09:42 +05:30
required: true,
description: copy_field_description(Types::MergeRequestType, :target_branch)
2021-10-27 15:23:28 +05:30
argument :description, GraphQL::Types::String,
2020-06-23 00:09:42 +05:30
required: false,
description: copy_field_description(Types::MergeRequestType, :description)
2021-10-27 15:23:28 +05:30
argument :labels, [GraphQL::Types::String],
2020-10-24 23:57:45 +05:30
required: false,
description: copy_field_description(Types::MergeRequestType, :labels)
2020-06-23 00:09:42 +05:30
field :merge_request,
Types::MergeRequestType,
null: true,
2021-10-27 15:23:28 +05:30
description: 'Merge request after mutation.'
2020-06-23 00:09:42 +05:30
authorize :create_merge_request_from
2020-10-24 23:57:45 +05:30
def resolve(project_path:, **attributes)
2021-03-11 19:13:27 +05:30
project = authorized_find!(project_path)
2020-10-24 23:57:45 +05:30
params = attributes.merge(author_id: current_user.id)
2020-06-23 00:09:42 +05:30
2021-06-08 01:23:25 +05:30
merge_request = ::MergeRequests::CreateService.new(project: project, current_user: current_user, params: params).execute
2020-06-23 00:09:42 +05:30
{
merge_request: merge_request.valid? ? merge_request : nil,
errors: errors_on_object(merge_request)
}
end
end
end
end